jasmine

[Unit test] jasmine createSpyObj

有些话、适合烂在心里 提交于 2019-12-12 21:09:06
beforeEach(() => { contextStub = { debug: false, engine: jasmine.createSpyObj('engine', [ 'createCollection', 'createContext', 'createSchematic', 'createSourceFromUrl', 'transformOptions', 'executePostTasks' ]), logger: jasmine.createSpyObj('logger', ['info']), schematic: jasmine.createSpyObj('schematic', ['call']), strategy: 0, interactive: false, addTask: jasmine.createSpy() }; }); it('schedules an npm install task if Material is not installed', () => { const rule = installMaterial(); rule(testTree, contextStub); expect(contextStub.addTask).toHaveBeenCalled(); expect(contextStub.logger.info)

Jasmine unit test case for dynamic character count

巧了我就是萌 提交于 2019-12-12 19:34:38
问题 Can anyone give me example of writing test case for checking if the function within the keyup event is called in jquery and jasmine. I am fairly new to jquery and jasmine so sorry for the errors. This program displays the remaining character count as the user enters the characters in the input field.and I'm stuck with test cases I tried as follows fixture.html : This is the fixture <input id="text" name="text" size="100" maxlength="65"></input> <span id="count"></span> script.js : This is the

Why I can't access global variable from javascript function in jasmine

你。 提交于 2019-12-12 19:32:01
问题 I'm using Jasmine standalone https://github.com/jasmine/jasmine/releases I have declared a global variable global_song in SpecRunner.html (I can access it from chrome console so it's truly global) which includes script where I am trying to concatenate global_song to "should be able to play Song " : it("should be able to play Song " + global_song, function() { player.play(song); expect(player.currentlyPlayingSong).toEqual(global_song); //demonstrates use of custom matcher expect(player)

Fake Ajax request

☆樱花仙子☆ 提交于 2019-12-12 18:22:11
问题 In order to check the submission of an ajax request, when a user submit a form, I implemented the following test using jasmine (1). The test is successfully passed but looking at javascript console I get the following error 500 (Internal Server Error) . Since I don't care the server response, my questions are: 1) Should I or should I not care about this error. 2) Will it be better to fake the ajax request to avoid Internal Server Error ? if yes, how in my context? (1) define([

Jasmine: Adding Lodash to Testing

淺唱寂寞╮ 提交于 2019-12-12 18:07:53
问题 I'm using lodash in my application/component. Jasmine is complaining: Failed: Cannot read property 'eq' of undefined I've added, lodash to my karma.conf such as:{ pattern: './node_modules/lodash/lodash.min.js', included: true, watched: false } Still getting the issue, what is the correct way of including lodash? 回答1: I solved this problem by adding these lines to "main.ts": main.ts //... import _ from 'lodash'; declare global { const _: _.LoDashStatic; } //... Also, I added lodash to karma

PhantomJs timeout

喜欢而已 提交于 2019-12-12 17:27:55
问题 I am using Jasmine with PhantomJS to run test cases. In my typical test case, I make a service call, wait for response and confirm response. Some requests can return in a few seconds and some can take up to a minute to return. When ran through PhantomJS, the test case fails for the service call that is supposed to take a minute ( fails because the response is not yet received). What's interesting is that the test passes when ran through Firefox. I have tried looking at tcpdump and the headers

'no method expect' when using Protractor as a library

左心房为你撑大大i 提交于 2019-12-12 17:06:54
问题 Using Protractor as a library Unable to require a reference to Jasmine. Referencing the expect method returns output Cannot call method 'expect' of null . Code updated to reflect comments: var protractor = require('protractor'); require('protractor/node_modules/minijasminenode'); require('protractor/jasminewd'); // output: jasmine is undefined (this error can only be seen if the above line is commented out) //expect(true).toBe(true); // output: Cannot call method 'expect' of null var driver =

How to test ngrx pipe select in Rxjs 6

被刻印的时光 ゝ 提交于 2019-12-12 13:57:39
问题 Previously I could test the below store select this.store.select(fromRoot.someselector).pipe(map(r => this.store.dispatch(new Action()))); This was in my test {provide: Store, useValue: jasmine.createSpyObj('store', ['select']); store.select.and.returnValue(of({})); But now it has changed to pipes this.store.pipe(select(fromRoot.someselector)); this.store.pipe( select(fromRoot.someselector), filter(result => !!result), map(r => { if (result === ' hello') { this.store.dispatch(new Action()); }

AngularJS + Jasmine + JWT Token in $http requests

一笑奈何 提交于 2019-12-12 13:51:16
问题 I'm trying to build some test with an API that works with JWT authentication tokens, but the factories that I'm trying to test use $resouce , which needs to be configured with JWT Token . In the app I configure it in the .config , but in Jasmine I have no idea how it should be, because Jasmine runs before the app. I'm trying to find the way to configure Jasmine's requests or maybe run the tests after the app is configured. Here I'm trying to configure the Jasmine 's requests. describe("Sync

No message in 10000 ms. Jasmine Karma RequireJSS

霸气de小男生 提交于 2019-12-12 13:33:41
问题 I started without knowing much in AngularJS. When I run : .\node_modules\.bin\karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=PhantomJS I get the following message : WARN [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Disconnected (1 times), because no message in 10000 ms. I started with the angular-seed project, from there I made adjustment for my needs. I want to use jasmine as my testing framework. So I made my test case based on the current angular-seed one: