jasmine

What do jasmine runs and waitsFor actually do?

扶醉桌前 提交于 2019-12-18 14:12:22
问题 I use jasmine runs and wait to test asynchronous operations. Everything works fine but I'm not quite sure what goes on behind the scenes. The jasmine documentation states the following example to which I added three log statement. describe("Asynchronous specs", function() { var value, flag; it("should support async execution of test preparation and exepectations", function() { runs(function() { flag = false; value = 0; setTimeout(function() { flag = true; }, 500); }); waitsFor(function() {

What do jasmine runs and waitsFor actually do?

倖福魔咒の 提交于 2019-12-18 14:12:16
问题 I use jasmine runs and wait to test asynchronous operations. Everything works fine but I'm not quite sure what goes on behind the scenes. The jasmine documentation states the following example to which I added three log statement. describe("Asynchronous specs", function() { var value, flag; it("should support async execution of test preparation and exepectations", function() { runs(function() { flag = false; value = 0; setTimeout(function() { flag = true; }, 500); }); waitsFor(function() {

ERROR in [at-loader] node_modules\@types\jasmine

一个人想着一个人 提交于 2019-12-18 12:16:50
问题 My webpack build started failing out of nowhere with no packages being updated. I assume some minor version update caused this, but can't figure out how to get around it. Does anyone know what to do? ERROR in [at-loader] node_modules\@types\jasmine\index.d.ts:39:52 TS1005: '=' expected. ERROR in [at-loader] node_modules\@types\jasmine\index.d.ts:39:38 TS2371: A parameter initializer is only allowed in a function or constructor implementation. ERROR in [at-loader] node_modules\@types\jasmine

Unit testing an observable in Angular 2

拥有回忆 提交于 2019-12-18 10:58:37
问题 What is the correct way of unit testing a service returning an Observable result in Angular 2? Let's say we have a getCars method in a CarService service class: ... export class CarService{ ... getCars():Observable<any>{ return this.http.get("http://someurl/cars").map( res => res.json() ); } ... } If I try to write the tests in the following way I get the warning: 'SPEC HAS NO EXPECTATIONS': it('retrieves all the cars', inject( [CarService], ( carService ) => { carService.getCars().subscribe(

How to test behavior in the link function of a directive

最后都变了- 提交于 2019-12-18 10:29:10
问题 In some of my directives, I'm adding functions to the scope to handle logic specific for the directive. For example: link: function(scope, element, attrs) { scope.doStuff = function() { //do a bunch of stuff I want to test } } How do I go about testing that function? I googled around for how test a directive, but the things I found were more about testing changes on the element. I can certainly compile my directive before each of my tests, but that would wipe out my scope every time. I want

How do you debug Jasmine tests with Resharper?

≡放荡痞女 提交于 2019-12-18 10:24:30
问题 I can't find a way to debug (walk through) JavaScript code when running Jasmine tests with Resharper in Visual Studio 2012. I tried running tests with browser (Chrome) but the test runner closes the port as soon as the test is run and so I cannot put a breakpoint in the code. Also tried running in Internet Explorer and put breakpoints in Visual Studio but it won't attach to the process. My test has a lot of ///reference scripts that Resharper includes automatically in the test runner but I

angular2 test, how do I mock sub component

孤街醉人 提交于 2019-12-18 10:02:32
问题 How do I mock sub component in jasmine tests? I have MyComponent , which uses MyNavbarComponent and MyToolbarComponent import {Component} from 'angular2/core'; import {MyNavbarComponent} from './my-navbar.component'; import {MyToolbarComponent} from './my-toolbar.component'; @Component({ selector: 'my-app', template: ` <my-toolbar></my-toolbar> {{foo}} <my-navbar></my-navbar> `, directives: [MyNavbarComponent, MyToolbarComponent] }) export class MyComponent {} When I test this component, I do

Jasmine get current test result

两盒软妹~` 提交于 2019-12-18 09:29:10
问题 I am using Jasmine - 3.3.1, with combination of ProtractorJS. My requirement is to store the result for each spec (or describe / test) and update results in Testrail system using the afterEach() method. I want to store the results into the variable "testResult". Tried with various methods - custom_reports.js etc, but could not get what I needed. Code snippet: var testResult; describe('1st scenario', function () { it('1st Test', function () { expect(true).toBe(true); testResult=5; }); });

Angular2 2.0.0 Component Unit Test causes error: Bootstrap at least one component before injecting Router

余生颓废 提交于 2019-12-18 09:04:42
问题 Looking at previous similar questions, it doesn't seem that there was ever a clear answer for this. Here's what's happening. I'm building an angular2 app using the angular-cli tool (beta 16 running, with angular 2.0.1 and router 3.0.1. When I run "ng test" all my tests pass, expect my app.component. (ng serve is working fine etc) Here's some code: app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { Routes, RouterModule }

ReferenceError: Can't find variable: Map

被刻印的时光 ゝ 提交于 2019-12-18 08:31:17
问题 I'm using Angular 4, Webpack 2.4.1, Karma 1.6 and Jasmine 2.6.1 and am writing ES2015 not TypeScript I've got a tiny angular demo app and I want to add unit tests. The demo app itself itself is working and Webpack is bundling everything correctly, but when I try to run the unit tests I see some errors in the console like this: ReferenceError: Can't find variable: Map at Static/js/app.welcome.js:2569 ( app.welcome.js is the name of my component) Webpack appears to be building my test bundle