angular-mock

Issue with angular.mock.inject method

若如初见. 提交于 2019-12-03 22:34:47
问题 I am using folloing jasmine test case 'use strict'; describe('companyService', function() { var $httpBackend, companyService; beforeEach(angular.mock.module('myApp')); beforeEach(angular.mock.inject(function(_$httpBackend_ , _companyService_) { $httpBackend = _$httpBackend_; companyService = _companyService_; })); it('should return a promise for getCompany function', function() { // expect(typeof companyService.getCompany('foobar').then).toBe('function'); }); }); i am getting the following

Unit testing Angular Directives with Jest

让人想犯罪 __ 提交于 2019-12-03 13:50:38
问题 I feel I am missing something crucial in this extremely simplified angular directive unit test: import * as angular from 'angular' import 'angular-mocks' const app = angular.module('my-app', []) app.directive('myDirective', () => ({ template: 'this does not work either', link: (scope, element) => { // have also tried compile fn console.log('This does not log') element.html('Hi!') } })) describe('myDirective', () => { var element, scope beforeEach(app) beforeEach(inject(($rootScope, $compile)

Issue with angular.mock.inject method

微笑、不失礼 提交于 2019-12-01 02:03:48
I am using folloing jasmine test case 'use strict'; describe('companyService', function() { var $httpBackend, companyService; beforeEach(angular.mock.module('myApp')); beforeEach(angular.mock.inject(function(_$httpBackend_ , _companyService_) { $httpBackend = _$httpBackend_; companyService = _companyService_; })); it('should return a promise for getCompany function', function() { // expect(typeof companyService.getCompany('foobar').then).toBe('function'); }); }); i am getting the following error . as you can see above . i am not doing anything inside it block . minErr/<@C:/Users/userone

How to Jasmine test code within angular module run block

狂风中的少年 提交于 2019-11-30 18:28:44
I would like to Jasmine test that Welcome.go has been called. Welcome is an angular service. angular.module('welcome',[]) .run(function(Welcome) { Welcome.go(); }); This is my test so far: describe('module: welcome', function () { beforeEach(module('welcome')); var Welcome; beforeEach(inject(function(_Welcome_) { Welcome = _Welcome_; spyOn(Welcome, 'go'); })); it('should call Welcome.go', function() { expect(Welcome.go).toHaveBeenCalled(); }); }); Note: welcome (lowercase w) is the module Welcome (uppercase W) is the service Managed to figure it out. Here is what I came up with: 'use strict';

What is the difference between expect and when in $httpBackend

☆樱花仙子☆ 提交于 2019-11-30 13:44:19
问题 What is the difference between $httpBackend.when('') and $httpBackend.expect('') ? I don't know the difference between these two methods. Also the angularjs api doc does not help me. API documentation link : https://docs.angularjs.org/api/ngMock/service/$httpBackend 回答1: $httpBackend.expect - specifies a request expectation $httpBackend.when - specifies a backend definition From: https://docs.angularjs.org/api/ngMock/service/$httpBackend Request expectations provide a way to make assertions