Menu
  • HOME
  • TAGS

ember event trigger order is different in app and tests

ember.js,qunit,ember-qunit,ember-testing

the click event doesn't set focus (being a back door route). You'll need to manually set focus then click if you want the same results. Ember's Click Helper (sends mousedown/mouseup, then click) function click(app, selector, context) { var $el = app.testHelpers.findWithAssert(selector, context); run($el, 'mousedown'); if ($el.is(':input')) { var type =...

how to check error in qunit

javascript,qunit,q

There are lots of problems here. For one, you don't have any way to let the calling code know that your function has finished. Without that, QUnit can't determine when to run the assertions. Then you'll need to use QUnit's async ability, otherwise the test function finishes before your promise...

save_and_open_page with ember-cli?

ember.js,rspec,qunit,poltergeist

test('clicking login authenticates', function(){ visit('/'); return pauseTest(); // The test will never proceed to execute this click click('a:contains(Login)'); }); Try to use pauseTest() while running the tests in the web browser: ember test --server The small window in the browser should pause and you can see its state. P.S. You...

Can't use jQuery referenced from a http url in a QUnit test

javascript,testing,qunit

I'm assuming you are doing .NET development in Visual Studio? That's the only place I've seen the /// <reference ... /> stuff. That is not actually including the source in your page, it is only used for the IntelliSense reference in your IDE. If you want to iunclude jQuery in...

How to unit test javascript function that calls getJSON

javascript,unit-testing,phantomjs,getjson,qunit

Your login function should be asynchronous, because its result depends on a response from server. So let's rewrite the function like this: function login(user, pass, done) { $.getJSON(..., function (res) { done(res.status == 'success') }) } Then you can test like this (assuming mocha): describe('...', function () { it('login()', function...

ReSharper's is not working with local paths

javascript,unit-testing,jasmine,resharper,qunit

It's fixed in ReSharper 9.1.1!

Testing Emberjs app using QUnit and Karma fails due to `ReferenceError: Faye is not defined`

ember.js,variable-scope,qunit,faye,karma-qunit

The reason of that weird behavior is related to the following lines in Faye: if (typeof module !== 'undefined') module.exports = Faye; else if (typeof window !== 'undefined') window.Faye = Faye; Source: https://github.com/faye/faye/blob/master/javascript/faye.js#L143 So if module is not undefined(meaning it is defined) then module.exports will be set object, if not,...

How can I trigger a TouchEvent in a grunt-run qunit test with plain javascript?

javascript,node.js,unit-testing,gruntjs,qunit

Are you using document.createTouch correctly? According to Safari developer you need to pass the view in which the event occurs (window). createTouch( DOMWindow view, EventTarget target, long identifier, long pageX, long pageY, long screenX, long screenY) touch1 = document.createTouch(window, div, 1, 0, 0, 0, 0); ...

nodejs + qunit: saving returned exception in test

javascript,node.js,qunit

It took a little bit of rethinking.. The quinit exception mechanism is a bit rudimentary for my needs.. This is the solution I reverted to, which is the test code started with before moving to qunit. There is one drawback, qunit will dump the backtrace if: QUnit.config.notrycatch = true; QUnit.test("Internal...

QUnit how to test events?

jquery,unit-testing,qunit

OK, I ended up just adding the button within the body of the test html document rather than through the qunit-fixture element. Now $("#btnSubmit").trigger("click"); triggers the actual event handler within the JS file under test. Oh, one other thing I did was mark the button as hidden which isn't necessary,...

Ember Qunit helpers not working

ember.js,qunit,ember-testing

The ember-qunit library that you are looking for can be downloaded from GitHub: https://github.com/rwjblue/ember-qunit-builds You can either access the library remotely: <script src="https://github.com/rwjblue/ember-qunit-builds/blob/master/ember-qunit.js"></script> Or you can download it locally, place it alongside your other scripts and include it by specifying the relative path to the library, replacing the remote path...

Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out

sapui5,qunit,openui5

teardonw removes the iframe and in the next test you have to bring it up again. This way you can write separated tests that can be run standalone. An example is here: Opa sample with 2 isolated tests If you press the rerun button on test2 it will execute standalone...

Triggering JavaScript events in Qunit tests

javascript,jquery,qunit

function setupModule() { $('input[name="text"]').on('click', function() { $('.has-error').hide(); }) $('input[name="text"]').on('keypress', function() { $('.has-error').hide(); }); } module('tests', {setup:setupModule}); test("errors should be hidden on key press", function() { $('input[name="text"]').trigger('keypress') equal($('.has-error').is(':visible'), false); }); test("errors not be hidden unless there is a keypress", function() { equal($('.has-error').is(':visible'), true); }); test("errors should be hidden on click", function()...

Angular unit test works in browser but errors in Chutzpah

angularjs,angular-ui,qunit,chutzpah

The issue is one of .js loading order. When you are running with code coverage the blanket.js plugin will instrument your files and cause them to load asynchronously. Since you were excluding your test files from instrumentation it was loading it before the source file. To change this just allow...

Grunt Qunit exclude file(s)

gruntjs,phantomjs,qunit,grunt-contrib-qunit

The QUnit grunt task uses the same globbing pattern matcher as most other tasks. Therefore, you can simply add a negated pattern to your target array of URLs: qunit: { all: ['Test/**/*.html', '!Test/**/ToBeExcluded.html'] } ...

How to create QUnit tests with reference to another class?

javascript,visual-studio,unit-testing,qunit

You should add all the relevant logic of your application to your unit testing file so they all execute before you run your tests <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>QUnit Test Results</title> <link rel="stylesheet" href="/Content/qunit.css"> </head> <body> <div id="qunit"></div> <div id="qunit-fixture"></div> <script src="/Scripts/qunit.js"></script> <script src="/Scripts/PlayerSkill.js"></script> <script...

Define test variables in QUnit setup

javascript,scope,qunit

I just realized that it is more simpler than my previous answer. Just add all properties that you want to access in all other test of modules in current object. QUnit.module("unrelated test", { setup: function() { this.usedAcrossTests = "hello"; // add it to current context 'this' } }); And then...

'equal' is not defined : Ember-qunit does not seem to be importing

javascript,testing,ember.js,ember-cli,qunit

Author here! Sorry about it, I actually need to update the code since on the latest release the syntax for tests changed to match the upcoming version of QUNit. Now to use: equal, ok and the other QUnit's assertions, we have to do it through a param called assert in...

Ember.js QUnit Test Only Visible Elements With find()

javascript,ember.js,qunit

I wouldn't use inline styles--use CSS classes instead. In your view/component, just add classNameBindings: ['isVisible'],, and in your CSS you can use .is-visible { display: block; }. I would actually invert the logic on that, as something should be visible unless hidden, instead of hidden unless visible, but I think...

ember-cli extend assert with custom assertion helpers

javascript,ember.js,ember-cli,qunit,ember-qunit

The assert object is a singleton instance which you can gain access with QUnit.assert. So the following should work import QUnit from 'qunit'; QUnit.assert.controlDisabled = function(selector, message) { return this.ok(findWithAssert(selector).attr('disabled'), message); }; ...

QUnit and a fail JSONP scenario

jquery,ajax,json,jsonp,qunit

Knowing that the cause was that the JSONP call was failing on the background, in order to suppress this error during testing I had to add an error handler to the document object when the error was expected. errorNamespace = "error.test" $(document).on(errorNamespace, function(event) { ok(true, "Received expected error"); // Prevent...

How and when to use .on or Events : {} with backbone

javascript,backbone.js,qunit,sinon

The short answer is... events:{} This property is to capture the delegate events that happening in DOM(templates). e.g., button click event on()/bind() These methods is to capture internal events happening inside backbone eg., collection/model add event ...

Pass url parameter to qUnit test using Grunt

gruntjs,qunit

Adding this as an answer from my comment, but honestly, it's unfortunate that it should have to be this way... It looks like you'll have to use the full options object with the urls set. See this example on their Github page. And here it is with your example: grunt.initConfig({...

Using filter inside Ember.RSVP.hash fails to retrieve data in qunit test

javascript,ember.js,qunit

store.filter doesn't actually load the records, it will only return records that are already in the store. What you probably want to do is something like... App.BooksRoute = Ember.Route.extend({ model: function() { var id = 1; // note: filters "books" properly but doesn't work in qunit return Ember.RSVP.hash({ books: this.store.find('books').then(function(books){...

Inconsistency in Resharper's qunit test runner

resharper,qunit

I'm not sure if this is exactly how you want this to work, but I wanted to run a newer version of QUnit than the one that comes bundled with R#. The simplest solution I had was to include QUnit-1.17.1 into my project, and in the top of my JavaScript...

JQuery Unit Testing tooltips (jasmine, qunit, etc..)

javascript,jquery,unit-testing,qunit,jasmin

The jQuery team uses Qunit for their testing. When I work on jQuery plugins, I tend to use the same tools. Here is an example test in Qunit: //In your JS function myTestFunction() { //code here } //In test.js QUnit.test( 'My Tests: ', function( assert ) { 'use strict'; var...

HTML isn't updated by knockout in QUnit test

jquery,html,knockout.js,qunit

The test wasn't working on first try because of the order tests were ran. Subsequent run worked because failed test are run in first. So, my test weren't independent from each other because I declared variable "root" only once and applied the knockout binding. Because of this, each test leave...

jasmine 2.0 version of expect() in qunit

javascript,jasmine,qunit

I would recommend adding a callCount variable, and incrementing it by 1 each time a callback is invoked. Then you can expect(callCount).toBe(x) just before the call to done(). On the other hand, you can use Spies to achieve this as well: it("Should run callbacks with correct data", function(done){ var callback...

Sinon.js, QUnit, and Jquery. Attempting to verify posted data through FakeXMLHttpRequest

javascript,ajax,json,qunit,sinon

A couple comments on your test: jQuery ajax() documentation says that if the data parameter isn't a string, it will be converted to a query string using $.param(). You could avoid that conversion by passing a string. The last assert compares [Object].mockData to a variable named mockData. I'm guessing that's...

QUnit fixtures not being restored every time

javascript,jquery,qunit

I think QUnit removes the element you added in the fixture before it runs each test. So the "keypress" event handler added on document ready is removed by the time the 2nd test starts. It will work if you add the event handler at the start of each test, or...

How to debug ember integration test with Webstorm

ember.js,integration-testing,webstorm,ember-cli,qunit

You should have used ember to run your code. And you are running it as a simple node.js application (node foo-test.js). Moreover, Node won't accept EcmaScript 6 syntax unless being run with --harmony switch. Please make sure to update your run configuration accordingly (to run ember and pass your spec...

Asserting a specific stub call was made with the required arguments using sinon

unit-testing,qunit,sinon

You can use sinon.assert.callOrder(spy1, spy2, ...), or spy1.calledBefore(spy2) or spy2.calledAfter(spy1). These can also be used with the result of spy.calledWith(...), e.g. sinon.assert.callOrder(spy.withArgs('a'), spy.withArgs('b'))....

How to run qunit assertions on resolving a Promise

javascript,promise,qunit,rsvp.js,rsvp-promise

promises work by chaining. Promises are immutable wrappers over values. When you do: promise.then(function(e){ // do something }); You are not changing promise you are creating a new promise instead. Instead, you need to chain the promise: test('success test', function(assert) { assert.expect(1); var promise = loadGroups(testData); // return the `then`...

QUnit terminates when function with arg throws unless wrapped in anon function

javascript,testing,anonymous-function,qunit

TL;DR: This is exactly how the throws() assertion in QUnit is intended to work, and how it must work. Long, drawn out response: In your example you are calling the assertion with the result of the call to sometimesThrows(false). That is to say, in your example above, when you call...

Qunit Test Cases for the jqgrid

jqgrid,qunit

I have to start with the following words: I'm not good in QUnit. Nevertheless because I see that nobody else wrote an answer to you I decided to write my answer. The most problem is how to use unit tests. I know a lot of people who try to set...

How can I write tests that have setup and teardown operations that are asynchronous?

javascript,ajax,unit-testing,asynchronous,qunit

Similar to test methods, you can use stop and start in your teardown code to pause the test runner until your clean-up code is done (asyncTest does an implicit call to stop). QUnit uses a counting semaphore for stop/start calls, so you can call stop multiple times if you've got...

TypeError: Cannot read property 'apply' of undefined, using javascript apply in tests?

javascript,ember.js,qunit,ember-qunit

Initializers are not run in unit tests componentForModel, therefore this.convertPercentage is undefined (as the error suggests). So my suggestion is to import the function from your model and just attach it: import convertPercentage from "../utils/convert-percentage"; export default DS.Model.extend({ salesTaxPercent: function(key, value, previousValue) { return this.convertPercentage.apply(this, arguments); }.property('salesTax') }); https://github.com/rwjblue/ember-qunit/issues/149#event-261578363...

Unit test computed property on an Ember controller

unit-testing,ember.js,ember-cli,qunit,ember-qunit

Something along these lines maybe? import { moduleFor, test } from 'ember-qunit'; import Ember from 'ember'; var products = [ Ember.Object.create({ name: 'shoe', subTotal: 10 }), Ember.Object.create({ name: 'shirt', subTotal: 20 })]; var model = Ember.ArrayProxy.create({ content: Ember.A(products) }); moduleFor('controller:cart', { beforeEach() { this.controller = this.subject(); } }); test('cartTotal', function(assert)...

unit test case for Javascipt function which access HTML elements from FORM

javascript,unit-testing,symfony2,qunit

You're talking about keeping your tests atomic with respect to the DOM, which is great! Don't give up! The basic idea is to have a version of the form in a "fixture" that is reset before/after each test in order to not have one test affect another (ensuring atomicity). You...

Sinonjs fakeserver - multiple ajax calls

javascript,ajax,qunit,sinon

Hmm, I thought server.repond() was supposed to do that as well. In any case, I usually set up my fake server(s) to auto respond instead. Unless you need to inspect requests before responding this seems to be easier: var server; QUnit.module('fake server tests', { beforeEach: function() { server = sinon.fakeServer.create();...

How to write a failing test with ember to show pushObject is required (instead of just push)?

ember.js,qunit,ember-testing

Are you looking for a way to show that pushObject() works with observers, but modifying the array in other (non-Ember friendly) ways doesn't work? If so, I think this JSBin shows that. It seems as if a simple array bound to a Handlebars template is enough to show that push()...

Test hover CSS properties using QUnit

jquery,css,qunit

You can't as it is not a trusted event. Events that are generated by the user agent, either as a result of user interaction, or as a direct result of changes to the DOM, are trusted by the user agent with privileges that are not afforded to events generated by...