jasmine

Unit testing with Webpack, Jasmine (-core), typescript

前提是你 提交于 2019-12-01 17:49:44
问题 I have a project that is using webpack to bundle all code into a single file. The project is using Typescript and it is working fine at the moment. I've gone to add unit testing and jasmine seems to be the way (one of the many ways) forward. Its actually jasmine-core that is included in the package.json - not sure how much of a difference that makes. So running a very simple test such as it('true is true', function(){ expect(true).toEqual(true); }); works fine. But when I add tests that

Unit testing AngularJS with $httpBackend gives “Error: Unexpected Request”

纵饮孤独 提交于 2019-12-01 17:03:58
I'm gonna preface this question by saying I've already gotten a test to work for my "LoginCtrl" which performs almost the exact same task. I'm sure this is an issue of something really small I've overlooked. Thanks in advance for any help :) I've set the expected value/response for httpBackend for my test, but when I run httpBackend.flush() , it's as if I never set the expectation. Testing code: describe('user register', function () { var scope, RegisterCtrl, httpBackend, userJohnDoe, userJohnDoeRegistered, Restangular; // TEST beforeEach(module('LR.User.Register')); describe('RegisterCtrl',

Unit testing AngularJS with $httpBackend gives “Error: Unexpected Request”

为君一笑 提交于 2019-12-01 16:49:21
问题 I'm gonna preface this question by saying I've already gotten a test to work for my "LoginCtrl" which performs almost the exact same task. I'm sure this is an issue of something really small I've overlooked. Thanks in advance for any help :) I've set the expected value/response for httpBackend for my test, but when I run httpBackend.flush() , it's as if I never set the expectation. Testing code: describe('user register', function () { var scope, RegisterCtrl, httpBackend, userJohnDoe,

Jasmine: How to get name of current test

你离开我真会死。 提交于 2019-12-01 15:47:38
Is there a way of getting the name of the currently running test? Some (heavily simplified) code may help explain. I want to avoid the duplication of "test1" / "test2" in the calls to performTest : describe("some bogus tests", function () { function performTest(uniqueName, speed) { var result = functionUnderTest(uniqueName, speed); expect(result).toBeTruthy(); } it("test1", function () { performTest("test1", "fast"); }); it("test2", function () { performTest("test2", "slow"); }); }); UPDATE I see the information I need is in: jasmine.currentEnv_.currentSpec.description or probably better:

Create custom jasmine matcher using Typescript

旧巷老猫 提交于 2019-12-01 15:47:17
I'm using jasmine on an angular2 project and having some trouble writing a custom matcher for a test. I want to be able to compare two relatively complex objects. I found this article which claims to solve the issue but it simply results in a typescript error stating that it doesn't recognize the new method on jasmine's Matchers object. The relevant code is this: declare module jasmine { interface Matchers { toBeNumeric(): void; } } Another article gives a similar, but slightly different solution that gives the same error. declare namespace jasmine { interface Matchers { toHaveText(expected:

How to fix beforeEachProviders (deprecated on RC4)

岁酱吖の 提交于 2019-12-01 15:02:30
Ive just upgraded Angular2 from RC3 to RC4 ... import { expect, it, iit, xit, describe, ddescribe, xdescribe, beforeEach, beforeEachProviders, withProviders, async, inject } from '@angular/core/testing'; In my unit test I have the following code ... beforeEachProviders(() => [ {provide: Router, useClass: MockRouter} ]); This works fine but since moving to RC4 I have a deprecation warning on beforeEachProviders . Anyone know what the new way of doing things is? Or should I import beforeEachProviders from somewhere else instead of '@angular/core/testing'? mifish You will need to import

Create custom jasmine matcher using Typescript

谁说胖子不能爱 提交于 2019-12-01 14:20:05
问题 I'm using jasmine on an angular2 project and having some trouble writing a custom matcher for a test. I want to be able to compare two relatively complex objects. I found this article which claims to solve the issue but it simply results in a typescript error stating that it doesn't recognize the new method on jasmine's Matchers object. The relevant code is this: declare module jasmine { interface Matchers { toBeNumeric(): void; } } Another article gives a similar, but slightly different

Spec has no expectations - Jasmine testing the callback function

核能气质少年 提交于 2019-12-01 14:00:45
问题 I have a method which is being called using a d3 timer . Whenever the method is called, the method emits an object with a couple of values. One of the values increases over time. I would like to write a test to check whether the values are in the ascending order or not (i.e., increasing over time or not). So, to tackle this, In my test, I subscribe to the event emitter and inside the subscription, I am pushing the object which I receive into a local array. And then, I am expecting the array[i

How to unit test $http in angularjs and Jasmine

﹥>﹥吖頭↗ 提交于 2019-12-01 13:59:01
Here is my code, I've made a Plunker as the code is long: describe("create", function(){ it("Should be defined", function(){ expect(BaseService.create).toBeDefined(); }); it("it should POST to http://api.test.com/TEST/", function(){ /*** * * NOT TO SURE WHAT TO DO HERE * */ }) }); http://plnkr.co/edit/s8P2XlkfR6HfGuj8WIcb I am new to Unit Testing so I am having a bit of trouble working out how to assert the following: If the method is going to x url If the method is using x method (e.g. GET, PUT, POST or DELETE) If the data passed to the method is the same as the data that is sent in the call

How to test _.defer() using Jasmine, AngularJs

杀马特。学长 韩版系。学妹 提交于 2019-12-01 12:54:07
I already asked this question where the main point was scope doesn't exists in terminal but it exists in Chrome debugging tool. Despite the answers it didn't get fixed. The question is what is the right syntax to test the bellow directive, especially the line expect(scope.measurementScroll).toBe(true); . While digging through web i couldn't find any similar question most questions are related to $q.defer() where in my case there is underscore method _.defer() Controller 'use strict'; angular.module('myApp') .controller('MeasurementsTimelineCtrl', ['$scope', '$state', 'Measurements', function(