qunit

Take screenshot from Karma while running tests in PhantomJS 2?

时光毁灭记忆、已成空白 提交于 2019-12-21 04:19:15
问题 I need a way to take a screenshot during a test which uses QUnit and Karma to run inside PhantomJS 2.0.1 I've found this command: window.top.callPhantom('render'); That doesn't throw any error but doesn't seem to work, or at least, I don't know where to look for the taken screenshot. Any clue? 回答1: Found a way! Solution I had to edit my custom PhantomJS custom launcher adding an option: PhantomJSCustom: { base: 'PhantomJS', options: { onCallback: function(data){ if (data.type === "render") {

Access RequireJS path configuration

落爺英雄遲暮 提交于 2019-12-21 04:14:28
问题 I notice in the documentation there is a way to pass custom configuration into a module: requirejs.config({ baseUrl: './js', paths: { jquery: 'libs/jquery-1.9.1', jqueryui: 'libs/jquery-ui-1.9.2' }, config: { 'baz': { color: 'blue' } } }); Which you can then access from the module: define(['module'], function (module) { var color = module.config().color; // 'blue' }); But is there also a way to access the top-level paths configuration, something like this? define(['module', 'require'],

How to run QUnit test and get back test result in C# via JavaScript callback?

余生颓废 提交于 2019-12-21 02:38:20
问题 In my several projects, I use MVC pattern for separating code (of concerns) into 3 tiers. Both of Model and Control tiers run on C# so I use testing framework like MSTest or NUnit to validate functional requirement for these tiers. For View tiers, I use QUnit to test JavaScript files. However, I cannot execute QUnit as automated test because MSTest doesn't directly support for testing web page. I need to run it in MSTest like the following logic. [TestMethod] public void JavaScriptTest() {

QunitJS-Tests don't start: PhantomJS timed out, possibly due to a missing QUnit start() call

扶醉桌前 提交于 2019-12-20 06:36:29
问题 I have set up my test environment as described here with QunitJS + PhantomJS + GruntJS: http://jordankasper.com/blog/2013/04/automated-javascript-tests-using-grunt-phantomjs-and-qunit/ If I execute the tests (grunt task) locally everything works fine. But If I try to execute the tests on our buildserver it throws following error: I checked the URL and path several times and the html-document for starting the qunit tests is also available on the configured path on our build server. Any ideas

Asserting that a function throws exceptions with Qunit

强颜欢笑 提交于 2019-12-19 05:34:31
问题 I am new to Qunit and unit testing. I am trying to figure out what and how to test the following function. It does not do much at the moment but I wanted to assert that if I pass it incorrect values that errors are being thrown: function attrToggle (panel, attr) { 'use strict'; if (!panel) { throw new Error('Panel is not defined'); } if (!attr) { throw new Error('Attr is not defined'); } if (typeof panel !== 'string') { throw new Error('Panel is not a string'); } if (typeof attr !== 'string')

jQuery Ajax: Reference MVC controller url from App root

梦想的初衷 提交于 2019-12-19 02:27:09
问题 I have an ASP.NET MVC web application running from http://localhost/myappname . From jQuery, I make jQuery $.ajax() calls to return partial views based on some user action. I usually call this from a view in the same controller that contains the function I am calling via Ajax. For example, a view in my Home controller has the following function (which works well): function loadMyPartialView() { $.ajax({ type: 'GET', url: 'Home/GetNavigationTreePV/', success: function (data) { onSuccess(data);

ember render hbs swallowing thrown error

守給你的承諾、 提交于 2019-12-18 16:55:28
问题 I have a simple component integration test: test('it throws error my-custom-input is called', function(assert) { assert.throws(() => { this.render(hbs`{{my-custom-input}}`); }, /my-custom-input component error/, 'Error must have been thrown'); }); Source code of component.js is like: export default Ember.Component.extend({ layout, init() { this._super(...arguments); throw 'my-custom-input component error'; } } While my ember-cli version was 2.3.0, the test was passing. However, after I've

Testing within a javascript closure

一笑奈何 提交于 2019-12-18 12:56:11
问题 Is it possible to unit test javascript functions that exist within a closure, so for example, given the following: (function() { var a = function() { //do something } window.b = function() { // do something else } })(); Is it possible to unit test function a without exposing it? If not, is there a good way to expose a, but only in test mode? 回答1: Your anonymous function could take a parameter which would be undefined when not in test mode, and say this parameter would be an object, you could

Qunit parameterized tests and mocking

这一生的挚爱 提交于 2019-12-18 10:11:38
问题 I have two questions: Can you have parameterised unit tests in qunit? How do you do mocking with qunit e.g. mocking a getJSON call? Thanks 回答1: For mocking ajax requests, you can try something like this... Here's the function you want to test: var functionToTest = function () { $.ajax({ url: 'someUrl', type: 'POST', dataType: 'json', data: 'foo=1&foo=2&foo=3', success: function (data) { $('#main').html(data.someProp); } }); }; Here's the test case: test('ajax mock test', function () { var

grunt not running QUnit tests on phantom

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 20:22:34
问题 I've got a repository which is integrated with travis. I've got QUnit tests which I'd like to run from grunt/node server side and AMD (requirejs). This is the source of my AMD init.js: (function () { require.config({ baseUrl: "../src" }); require(["../test/suites/basic", '../test/qunit-extend', 'qunit' ], function(BasicTests) { QUnit.config.autoload = false; QUnit.config.autostart = false; BasicTests.run(); QUnit.load(); QUnit.start(); }); }()); When I run those QUnit tests within my browser