jasmine

How to test done part of ajax in jasmine

╄→尐↘猪︶ㄣ 提交于 2019-12-25 01:03:21
问题 I really like this resource for AJAX in general and it works in terms of testing a success or error function that's within the AJAX parameters. However, when I instead choose to not have a $.ajax({ ... success: ... }) and choose to have a .done() outside, I'm not sure how to test. Please help amend my simple spec, thanks! Code function itWorked() {} function sendRequest(callbacks, configuration) { $.ajax({}).done(function(response) { itWorked() }); } Spec fdescribe("Ajax Tests", function() {

Why is the jQuery code not executing, or at least not appearing to execute, in my jasmine test?

ⅰ亾dé卋堺 提交于 2019-12-25 00:55:56
问题 I am running Rails 3.2.8 with the jasmine-rails gem. Here are the lines from my Gemfile describing the jasmine set-up: jasmine (1.2.1) jasmine-core (>= 1.2.0) rack (~> 1.0) rspec (>= 1.3.1) selenium-webdriver (>= 0.1.3) jasmine-core (1.2.0) jasmine-headless-webkit (0.8.4) coffee-script jasmine-core (~> 1.1) multi_json rainbow sprockets (~> 2) jasmine-rails (0.1.0) jasmine jasmine-headless-webkit rails (>= 3.1.0) I am also using the jasmine-jquery extension. This set of functions provide the

how to mock/stub a node.js module

自作多情 提交于 2019-12-24 23:43:53
问题 I'm working on some code to run on RaspberryPi, and I'm using the Wiring-Pi node module. I have two problems 1) Wiring-Pi won't build on x86 platforms 2) Node-jasmine won't build on RaspberryPi So, after playing around with a bunch of different ideas, I'm wondering if I'm best off to mock or stub the Wiring-Pi module when on x86 platforms, so I can run the tests. Of course, my problem is that the file I'm testing includes the require statment // getters.js var wpi = require('wiring-pi'); //

Angular unit test spyOn not detecting my call

孤人 提交于 2019-12-24 19:24:55
问题 I've got a problem with a unit test I can't solve. Here is my test : fit('should call the alert service in case something went wrong getting the list of files', async(() => { spyOn(this.component.alert, 'error'); this.component.onInputChange('error'); this.fixture.whenStable().then((() => { expect(this.component.alert.error).toHaveBeenCalledWith('an error occured'); })); })); And here is the part of the component I'm testing : private onInputChange (search: string) { const that = this; this

How to unit test with Jasmine on multiple chained functions with returns?

a 夏天 提交于 2019-12-24 17:09:19
问题 I have the following function: /** * filters array down to the given allowed keys * @param {Object} data * @param {String[]} allowedKeys */ $scope.filterData = function(data, allowedKeys) { return Object.keys(data) .filter(function(key) { return allowedKeys.includes(key); }) .reduce(function(obj, key) { obj[key] = data[key]; return obj; }, {}); }; that I want to create a unit test for and so far I have the following: describe('$scope.filterData', function() { //params var data = { key1:

How to unit test with Jasmine on multiple chained functions with returns?

谁说胖子不能爱 提交于 2019-12-24 17:08:34
问题 I have the following function: /** * filters array down to the given allowed keys * @param {Object} data * @param {String[]} allowedKeys */ $scope.filterData = function(data, allowedKeys) { return Object.keys(data) .filter(function(key) { return allowedKeys.includes(key); }) .reduce(function(obj, key) { obj[key] = data[key]; return obj; }, {}); }; that I want to create a unit test for and so far I have the following: describe('$scope.filterData', function() { //params var data = { key1:

Unit Testing Model Binding in Angular 5 with Jasmine

坚强是说给别人听的谎言 提交于 2019-12-24 17:07:11
问题 I am trying to write a unit test that tests that the JSON data returned from the components method call successfully binds to a typescript model. My model looks like the following: export interface IPlayerAccount { playerId: number; name: string; phone: number; street: string; postcode: string; state: string; country: string; } This array of IPlayerAccount is populated on ngOnInit with method definition: getPlayerAccounts(playerId: number) Here is my Jasmine Unit Test to test that the json

Injected Dependency is undefined in Unit Test

你。 提交于 2019-12-24 15:15:47
问题 I'm new to Angular and I'm not quite sure exactly how dependency injection works. My problem is that I have Service A which depends on Service B, but when I inject Service A into my test Service B becomes undefined. I have seen Injecting dependent services when unit testing AngularJS services but that problem is a bit different than mine. This Injected Dependencies become undefined in angular service is very similar to my issue but I couldn't translate the JS. I have also changed my variable

How do I get a resource from an Angular.js module for a jasmine test

此生再无相见时 提交于 2019-12-24 13:57:19
问题 I have a module that contains resources for a project, and the code looks like this: editor_services.js var editorServices = angular.module('editorServices', ['ngResource']); editorServices.factory('Project', ['$resource', '$http',function($resource, $http){ //...etc now I would like to write tests for a controller that expects a project resource as an argument. How can I get an instance of the project resource that is created by this factory out of the editorServices variable? 回答1: Here is a

How I can I unit test that a function inside another function was called?

本小妞迷上赌 提交于 2019-12-24 12:13:49
问题 How I can I unit test that a function inside another function was called? I can't change the source code, so I need to test this as-is. How can I do this? Here's my code: function B(){ console.log('function b'); } function A(){ B(); } Jasmine test: it('should check function B in function A was called', function () { spyOn(window, 'B'); A(); expect(B).toHaveBeenCalled(); }); 回答1: Spies Jasmine has test double functions called spies. A spy can stub any function and tracks calls to it and all