jasmine

Testing Service. TypeError: done.fail is not a function

别说谁变了你拦得住时间么 提交于 2019-12-24 07:08:10
问题 I have tried this test, for testing my service: It has shown this error: TypeError: done.fail is not a function test file it('should return reasonable json ssss', inject([ProductService, MockBackend], async((service: ProductService, mockBackend: MockBackend) => { const mockResponse = { data: [ { id: 0, details: 'All cats are lions' }, { id: 1, details: 'Video 1' }, { id: 2, details: 'Video 2' }, { id: 3, details: 'Video 3' }, ] }; mockBackend.connections.subscribe(connection => { connection

how to access controller in directive [jasmine]

女生的网名这么多〃 提交于 2019-12-24 06:45:12
问题 I am having some difficulty accessing the methods and variables on a directive in order to test it. What am I doing wrong? I have attached my directive and the test file. I did not include my karma conf because I know it is correct and that is not the problem. accountsearch.spec.js <-- this is the file with test cases describe("Account search directive logic tests", function (){ var element,$scope,scope,controller,template beforeEach(module("Common.accountSearch")) beforeEach(inject( function

Angular6 Jasmine TypeError: expect(…).toBeVisible is not a function

霸气de小男生 提交于 2019-12-24 05:07:05
问题 Setting up jasmine-query-matches in angular6 On angular 5 project it looks at simple as import { } from 'jasmine-jquery/lib/jasmine-jquery'; import { } from 'jasmine-jquery-matchers'; import * as $ from 'jquery'; On angular 6 i have tried the following import {} from "jasmine-jquery/lib/jasmine-jquery" ; import {} from "jasmine-jquery-matchers/dist/jasmine-jquery-matchers" ; import { } from "karma-jasmine-jquery"; import * as $ from 'jquery'; OR import {} from "jasmine-jquery" ; import {}

Unit-Testing: Q.js & Jasmine.js

天大地大妈咪最大 提交于 2019-12-24 04:35:06
问题 I ported my library form jQuery to Q.js and at the same time re-wrote my unit-test from QUnit to Jasmine.js and now facing some issue: Because of the fact that all promise-objects are resolved async (setTimeout( func, 0 )) I have to write not so nice unit-tests with "runs" and "waitsFor". The "jasmine.Clock.useMock" approch is not working (at leased two weeks ago) So my question is how to test my library that uses Q.js with Jasmine.js? Update 1: You can find my unit-tests here. See test "'The

How can I mock ui-router's resolve values when testing a state's configuration?

别说谁变了你拦得住时间么 提交于 2019-12-24 04:23:11
问题 I'm writing an angular application using ui-router and I'm looking to write tests for my ui-router configuration. Specifically, I'm looking to test my onEnter and onExit callbacks bound to a state. These callbacks rely on resolves which are defined on the state. How can I mock out the resolves being used in the onEnter and onExit functions? For example, say I have a state defined as follows: // bobConfig.js .state('bob', { url: '/bob', templateUrl: "bob.html", controller: "bobController",

Unit testing a service in angularJS

◇◆丶佛笑我妖孽 提交于 2019-12-24 03:20:23
问题 I'm relatively new to unit testing but was now tasked to write tests for a existing code base that I know quite well. Sadly I'm unable to achieve any progress what so ever nor find really helpful documentation. The main component of the code base is a service to retrieve data from an api but I'm unable to get an instance of the module the service belongs to: TypeError: module is not a function in /home/faebser/workspace/GridSense-CMS-App/dev/test/unit/api.test.js (line 13) karma config: http:

How to programmatically find if a function is async?

我的未来我决定 提交于 2019-12-24 01:24:07
问题 I am trying to override (monkey patch) the it() function of the Jasmine framework and in the process, I want to know if a function which is passed as the second argument to the it() function is of type async or not. I tried using the instanceof Promise because all async functions return a promise, but it never resolves to true and it never goes into the if block in the following code block. I have tried logging all the functions to the console and I found that all the async() function specs

Do I have to inject the service in the unit test if I cal testBed.get() previously?

扶醉桌前 提交于 2019-12-24 00:46:07
问题 I have a service which I'm consuming in my angular 2 unit test. I call the service in the beforeEach block first with TestBed.get() Example : beforeEach(() => { fixture = TestBed.createComponent(ConfigComponent); component = fixture.componentInstance; service = TestBed.get(ConfigService); fixture.detectChanges(); }); I then use this service in the unit test like this: Example : it('should do something', inject([ConfigService], (configService) => { // code here })); Do I need to inject the

is not assignable to parameter of type 'Expected<Promise<string>>' in editor

跟風遠走 提交于 2019-12-24 00:44:40
问题 My tests are passing from command line, however I edit the typescript source using Atom . And when I open one of the test files in my editor, I'm seeing an error on this line: expect(pageObject.name.getText()).toEqual('Some name'); This is the error: Typescript Error Argument of type '"Some name"' is not assignable to parameter of type 'Expected<Promise<string>>'.at line 16 col 50 Why does this show in my editor? Yet tests pass. Command to run protractor tests: protractor dist/protractor

Wait for a module to be loaded to execute the tests it contains

梦想的初衷 提交于 2019-12-24 00:43:13
问题 My unit tests are contained into a module that loads from an HTML page using SystemJS. <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/rxjs/bundles/Rx.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> <script> System.config({ defaultJSExtensions: true,