jasmine

Mocking ngrx/store

若如初见. 提交于 2019-12-08 18:13:34
问题 This is in regards to the Angular 2 official release. I know that unit testing has changed drastically between beta, RC, and the official release. What's a good way to mock @ngrx/store in a unit test when it's used as a parameter in a constructor? It's not as simple as mocking a service. For example, if I wanted to mock a service, then I could do something like this: let serviceStub = { }; // not a true mocked service, just a stub, right? let de: DebugElement; let el: HTMLElement; let

Running spec after promise has been resolved

霸气de小男生 提交于 2019-12-08 18:08:26
I came across an issue with running a spec that should be executed after a promise has been resolved. See the commented simplified example below. I tried using IIFE or calling done() function in the spec but none of these seemed to work. // getIds() is a simple promise which returns an array of ids getIds().then(function (ids) { console.log('IDS: ' + ids); // all good so far // This test is never run it('dummy test', function () { console.log('TEST HAS BEEN RUN'); }); }); You can use browser.wait() to wait until your promise is complete. Or you can put your test inside the then block: it(

jasmine angularjs testing - Argument 'PhoneListCtrl' is not a function, got undefined

别说谁变了你拦得住时间么 提交于 2019-12-08 17:09:53
问题 When running an angularjs + Jasmine + Karma test, I got following error: My test script is: describe('PhoneCat controllers', function() { describe('PhoneListCtrl', function(){ it('should create "phones" model with 3 phones', inject(function($controller) { var scope = {}, ctrl = $controller('PhoneListCtrl', { $scope: scope }); expect(scope.phones.length).toBe(3); })); }); }); This code is just a copy from official AngularJS tutorial here: http://code.angularjs.org/1.2.0-rc.3/docs/tutorial/step

PhantomJS “Can't find variable: require” when using PhantomJasmine

…衆ロ難τιáo~ 提交于 2019-12-08 17:05:47
问题 I would like to use Phantomjs and Jasmine for unit testing javascript. Phantomjs's website recommends that I use a separate thing to handle this, specifically, PhantomJasmine. I downloaded PhantomJasmine and ran the example. Everything went perfectly. I then added the line var system = require('system'); to the top of example_spec.js. The Phantomjs now throws an error when I try to run the example I get "ReferenceError: Can't find variable: require". So, I want to do need things like launch

grunt jasmine-node tests are running twice

↘锁芯ラ 提交于 2019-12-08 16:55:40
问题 I set up grunt to run node.js jasmine tests. For some reason, with this config, the results always show double the tests. Here is my config: I'm using jasmine-node which plugs into grunt. /spec/some-spec.js : var myModule = require('../src/myModule.js'); describe('test', function(){ it('works', function(done){ setTimeout(function(){ expect(1).toBe(1); done(); }, 100); }); }); Gruntfile.js : module.exports = function(grunt) { grunt.initConfig({ jasmine_node: { options: { forceExit: true }, all

AngularJS directive link function not called in jasmine test

假如想象 提交于 2019-12-08 16:41:20
问题 I'm creating an element directive that calls a service in its link function: app.directive('depositList', ['depositService', function (depositService) { return { templateUrl: 'depositList.html', restrict: 'E', scope: { status: '@status', title: '@title' }, link: function (scope) { scope.depositsInfo = depositService.getDeposits({ status: scope.status }); } }; }]); The service is trivial for now: app.factory('depositService', function(){ return { getDeposits: function(criteria){ return 'you

how to remove Unexpected request: GET data.json?

こ雲淡風輕ζ 提交于 2019-12-08 16:30:31
I am trying to use $httpBackend to test my $http request ..i AM getting this error Unexpected request: GET data.json No more request expected here is my testing code beforeEach(inject(function($rootScope,$controller,appfactory,_$httpBackend_) { $scope = $rootScope.$new(); $httpBackend=_$httpBackend_; ctrl = $controller('cntrl', {$scope: $scope}); fac=appfactory; modeSpy= spyOn(fac, 'mode').and.returnValue('a'); })); it('test true value',function(){ expect(true).toBeTruthy() }) it('check message value',function(){ $scope.toggle(); expect($scope.message).toEqual('naveen') }) it("tracks that the

Why does running `jasmine` after `jasmine init` and `jasmine examples` do nothing?

别说谁变了你拦得住时间么 提交于 2019-12-08 15:41:01
问题 I have globally installed jasmine by running npm install jasmine -g . Running jasmine -v gives me jasmine v2.5.0 jasmine-core v2.5.0 I have then, as per the docs, run jasmine init jasmine examples This created the expected /spec directory and the spec/support/jasmine.json file. I am under the impression that if I now run jasmine I should see some test output in the console. Instead it simply thinks about it for a second and then does nothing. I'm running node v4.5.0 on a Windows 7 machine in

How to unit test a Angular 4 component which uses router.paramMap

守給你的承諾、 提交于 2019-12-08 15:13:21
问题 I m new to angular 4 and trying to test one of the angular 4 feature router.paramMap from unit tests, Reading route params in fallowing way and working as expected in my application. constructor(private router:Router, private actRoute:ActivatedRoute) { } ngOnInit() { this.router.paramMap.subscribe(params => { params.get(id); }) ...... } But while running unit test, i m getting error which says cannot call subscribe method of undefined even though i m passing passing route param as below. {

Why do I have to call spyOn in a beforeEach()?

泄露秘密 提交于 2019-12-08 14:58:36
问题 I have a simple test suite that has one it function inside of it. I want to see if a certain function is called within the function I'm calling, so I have something like this: describe("doStuff", function () { var foo = new Foo(); spyOn(foo, "doOtherStuff"); foo.doStuff(true); it("should do stuff and other stuff", function() { expect(foo.stuffDone).toBe(true); expect(foo.doOtherStuff).toHaveBeenCalled(); }); }); However, this gives me the error: Expected a spy, but got Function. After looking