jasmine

Angular Material and Jasmine : “ No provider for InjectionToken MdDialogData! ”

我怕爱的太早我们不能终老 提交于 2020-01-11 21:09:39
问题 I have a component which is meant to be used in an Angular Material MdDialog : @Component({ ... }) export class MyComponent { constructor(@Inject(MD_DIALOG_DATA) public data: any, public dialogRef: MdDialogRef<MyComponent>) { ... } } I am trying to Unit Test it with Jasmine : describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ SharedTestingModule, ], declarations: [

Expect not toThrow function with arguments - Jasmine

此生再无相见时 提交于 2020-01-10 12:12:29
问题 I have function that gets 3 arguments. I want to check that this function not throwing an error. I did something like this: expect(myFunc).not.toThrow(); The problem is myFunc need to get arguments. How can I send the arguments? P.S I tried to pass it argument but I got error that myFunc(arg1, arg2, arg3) is not a function. 回答1: toThrow matcher requires function to be passed as argument to expect so you can simply wrap your function call in anonymous function: expect(function() { myFunc(arg1,

Expect not toThrow function with arguments - Jasmine

烂漫一生 提交于 2020-01-10 12:11:22
问题 I have function that gets 3 arguments. I want to check that this function not throwing an error. I did something like this: expect(myFunc).not.toThrow(); The problem is myFunc need to get arguments. How can I send the arguments? P.S I tried to pass it argument but I got error that myFunc(arg1, arg2, arg3) is not a function. 回答1: toThrow matcher requires function to be passed as argument to expect so you can simply wrap your function call in anonymous function: expect(function() { myFunc(arg1,

Mocking HTTP service unit test with AngularJS and Jasmine

拜拜、爱过 提交于 2020-01-07 07:36:11
问题 I am attempting to build a mock service so that my unit tests can verify certain functions are called and updated accordingly. Unfortunately I cannot get this to work. Im currently getting an error undefined is not a function on this line: spyOn(statusService, 'getModuleStatus').andCallThrough(); My actual service looks like this: serviceStatusServices.factory('serviceStatusAppAPIservice', function ($http) { var serviceStatusAppAPI = {}; serviceStatusAppAPI.getModuleStatus = function () {

undefined|0|ReferenceError: Strict mode forbids implicit creation of global property 'csrf_token'

此生再无相见时 提交于 2020-01-07 04:41:06
问题 So, this was quite an interesting problem I have been running into. I am currently building a backbone.js - Rails app. Generally just building this for learning purposes. I am (like any good rails dev) doing my best at TDD/BDD and I ran into a problem with capybara. I have an integration spec that merely tests root_path works (Backbone history starts, displays initial information, etc...). require 'spec_helper' describe "RentalProperties", js: true do describe "GET /" do it "should show a

simulating two observables emiting successively

一世执手 提交于 2020-01-07 00:54:19
问题 I have a component that has two properties that are observables @Component({ }) export class MyComponent { observable1$; observable1$; ngOnInit() { Observable1$ = this.service.getObservable1(); Observable2$ = this.service.getObservable2(); } } I practice, observable2$ will emit bar only after observable1$ emits foo . How can I write a test that simulates this? If I write in my spec mockService.getObservable1.and.returnValue(Observable.of('foo')) mockService.getObservable2.and.returnValue

How to unit test Promise catch using Jasmine

旧街凉风 提交于 2020-01-06 14:00:33
问题 I have a very simple function load() that I'm trying to unit test with Jasmine. this.service.loadObject() returns a Promise. How can I test that this.logService.error will be called if the Promise is rejected ? load() { this.service.loadObject().then(x => { this.variable = x; }).catch(ex => this.logService.error(ex)); } 回答1: Something like this should work: it("should catch the error", done => { spyOn(service, "loadObject").and.returnValue(Promise.reject("test error")); spyOn(logService,

How can I get Meteor (client) unit tests (using Velocity with Jasmine) to work in Cordova on device?

旧巷老猫 提交于 2020-01-06 07:39:21
问题 I have a mobile Meteor project (Cordova + Ionic Framework + Angular-Meteor) with unit-tests set up with Velocity and Jasmine. When testing in the browser, the client tests execute as expected but fail on mobile devices. The test servers are hosted at localhost so the devices can't find my computer which hosts the app and test servers. How can I change the Velocity test servers host from localhost to my LAN IP address? 回答1: You need to set your ROOT_URL environment variable. I found that if my

AngularJs + Jasmin : testing a function wchich does not return anything but calls another function for validation and a factory service

夙愿已清 提交于 2020-01-06 07:11:08
问题 I am trying to test this createParameterGroup function which is calling a private function, When I try to test this createParameterGroup function, it gives an error saying that validateParameterGroup is not a function. controller angular.module('PpmApp') .controller('parameterGroupListController', ['$scope', '$injector', 'parameterGroups', parameterGroupListController]); function parameterGroupListController($scope, $injector, parameterGroups) { $scope.createParameterGroup = function

AngularJs + Jasmin : testing a function wchich does not return anything but calls another function for validation and a factory service

不打扰是莪最后的温柔 提交于 2020-01-06 07:02:02
问题 I am trying to test this createParameterGroup function which is calling a private function, When I try to test this createParameterGroup function, it gives an error saying that validateParameterGroup is not a function. controller angular.module('PpmApp') .controller('parameterGroupListController', ['$scope', '$injector', 'parameterGroups', parameterGroupListController]); function parameterGroupListController($scope, $injector, parameterGroups) { $scope.createParameterGroup = function