jasmine

Cleaning up Protractor stack trace

℡╲_俬逩灬. 提交于 2019-12-07 06:15:33
问题 The Question: Is it possible to clean up the stack trace and leave only relevant frames eliminating everything Protractor , WebDriverJS and Jasmine specific? The Story: Let's execute this example test: describe("SO test", function () { beforeEach(function () { browser.get("https://angularjs.org"); }); it("should throw a meaningful error", function () { element(by.id("not_found")).click(); }); }); It would fail with a following stacktrace: SO test should throw a meaningful error - Failed: No

Disable Jest setTimeout mock

萝らか妹 提交于 2019-12-07 05:49:15
问题 I'm writing a Jest test for code that depends on a websocket library. The websocket library is mocked. I want to send a message, wait for async actions to complete, and check the response. it('sends a message and gets a response', () => { processor(ws).sendMessage() // do a bunch of async stuff, call websocket.sendMessage() setTimeout(() => { expect(ws.getResponse()).toEqual('all done') }, 100) }) Unfortunately because Jest mocks setTimeout, setTimeout fails. If I run jest.runAllTimers() ,

Why call scope.$digest() after $compile(element)(scope) in unit testing

孤街醉人 提交于 2019-12-07 05:42:21
问题 Below is a very common generic scenario used for testing directive: var element,scope; beforeEach(inject(function ($rootScope,$compile) { scope = $rootScope.$new() element = angular.element('<div my-directive></div>') $compile(element)(scope) scope.$digest(); //why? })) I understand $compile(element) returns a function that take a scope parameter and provides it to the element's directive. I also understand that scope.$digest() executes the digest loop and start dirty-checking. With all that

Browser page keeps refreshing when testing Backbone views with Jasmine

荒凉一梦 提交于 2019-12-07 05:21:27
问题 Running the following Jasmine test(1), the test is successfully performed but I face the recursive loading of the main test page. Here is my test (1) and here the module on which I am running the test (2): Any ideas? How can I fix the issue? P.S.: The issue regard just Chrome and Safari Browser. Here is an example: jsfiddle.net/shioyama/EXvZY (1) describe('When Submit button handler fired', function () { beforeEach(function () { spyOn(MyView.prototype, 'submitForm'); this.view = new MyView();

Jasmine js: Add source method for test execution

随声附和 提交于 2019-12-07 05:06:01
问题 I have as simple "hello world" project and I want to test the famous hélloWorld function. The project is structured like this: ├── package.json ├── spec │ ├── helloWorldSpec.js │ └── support │ └── jasmine.json └── src └── helloWorld.js And the file content: package.json { "name": "jasmineTest", "version": "0.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "BSD-2-Clause", "dependencies": { "jasmine": "

d3 transition in unit-testing

主宰稳场 提交于 2019-12-07 03:55:44
问题 I have an chart built by d3 and which appears with transitions and I need to test chart when all transitions have ended. I use jasmine for unit-testing. How to do it? I find method d3.timer.flush() , but it skips only first frame, but I want to skip all animations and see an final result right now and make some assertions on it. 回答1: You can execute transitions synchronously directly to their final state with one call to D3's timer flush if you mock out its timestamp determination during the

Unit test Angular 2 service subject

亡梦爱人 提交于 2019-12-07 03:35:49
问题 I'm trying to write a test for an angular service which has a Subject property and a method to call .next() on that subject. The service is the following: @Injectable() export class SubjectService { serviceSubjectProperty$: Subject<any> = new Subject(); callNextOnSubject(data: any) { this.serviceSubjectProperty$.next(data); } } And the test file for that service: import { TestBed, inject } from '@angular/core/testing'; import { SubjectService } from './subject.service'; describe(

Angular Testing: FormControl valueChanges Observable

僤鯓⒐⒋嵵緔 提交于 2019-12-07 03:10:22
问题 I have a text input and I'm listening for the changes. component name = new FormControl('',Validators.required); ngOnInit() { this.data = 'oldvalue'; this.checkName(); } checkName() { this.name.valueChanges.subscribe(val=>{ console.log(val); this.data= "newvalue"; // updating Value }); } HTML <input name="name" formControlName="name"> My Attempt so far: component.spec.ts it('should test data field ', () => { const fixture = TestBed.createComponent(UserComponent); const app=fixture

AngularJS inject service mock inside service tests

落爺英雄遲暮 提交于 2019-12-07 02:28:14
问题 I have been trying to test a service to no avail for some time now and was hoping for some help. Here is my situation: I have a service looking a little like this myModule.factory('myService', ['$rootScope', '$routeParams', '$location', function($rootScope, $routeParams, $location) { var mySvc = { params: {} } // Listen to route changes. $rootScope.$on('$routeUpdate', mySvc.updateHandler); // Update @params when route changes mySvc.updateHandler = function(){ ... }; ... ... return mySvc; }]);

Can't set timeout for jasmine

对着背影说爱祢 提交于 2019-12-07 01:33:54
问题 I've tried all the solutions in this answer but none of them work for me. I'm using jasmine v2.3.2 and jasmine-core v2.3.4 When I do this test: jasmine.DEFAULT_TIMEOUT_INTERVAL= 999999; describe('tests content controller', function(){ //... fit('/content should return 200',function(done){ request(app) .get('/content?type=script') .set('Authorization', "bearer " + requestor.token) .set('Accept', 'application/json') .expect(200) .end(function (err, res) { if (err) done.fail(err); expect(res