jasmine

Mock date constructor with Jasmine

一笑奈何 提交于 2019-12-01 02:42:41
I'm testing a function that takes a date as an optional argument. I want to assert that a new Date object is created if the function is called without the argument. var foo = function (date) { var d = date || new Date(); return d.toISOString(); } How do I assert that new Date is called? So far, I've got something like this: it('formats today like ISO-8601', function () { spyOn(Date, 'prototype'); expect().toHaveBeenCalled(); }); See: https://github.com/pivotal/jasmine/wiki/Spies Credit to @HMR. Test I wrote to verify: it('Should spy on Date', function() { var oldDate = Date; spyOn(window,

Angular 2 Jasmine Can't bind to 'routerLink' since it isn't a known property of 'a'

孤人 提交于 2019-12-01 02:42:22
I'm creating a unit test for my Navbar Component and I'm getting an error: Can't bind to 'routerLink' since it isn't a known property of 'a' Navbar Component TS import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { NavActiveService } from '../../../services/navactive.service'; import { GlobalEventsManager } from '../../../services/GlobalEventsManager'; @Component({ moduleId: module.id, selector: 'my-navbar', templateUrl: 'navbar.component.html', styleUrls:['navbar.component.css'], providers: [NavActiveService] }) export class NavComponent { showNavBar:

前端单元测试工具karma

本秂侑毒 提交于 2019-12-01 02:33:00
Jasmine是一个很好的单元测试框架,它有漂亮简单的API describe('you can group test cases in "describe" blocks...', function() {     describe('...which can also be nested', function() {         it('test cases are in "it" blocks', function() {         var string = 'where we can run arbitrary JavaScript code...'; // ...and make assertions about results using "expect":         expect(string).toEqual('expected string');       });     }); });    Karma 是一个集成了像 Jasmine(基于 BDD 的测试框架),PhantomJS(无界面的浏览器)等的测试工具。 npm安装好后,就要写karma的配置文件 //karma.conf.js module.exports = function(config) { config.set({ frameworks: ['jasmine'], files

What is the difference between testbed.get and inject in Angular 2/Jasmine testing?

只谈情不闲聊 提交于 2019-12-01 02:14:53
I am new to Angular 2 testing. I am trying to figure out what is the difference in using testsbed.get() and just using inject at the test level. eg: beforeEach(() => { TestBed.configureTestingModule({ providers: [SomeService] }); const testbed = getTestBed(); someService= testbed.get(SomeService); }); }); vs it('test service', inject([SomeService], (someService: SomeService) => { inject helper function was historically used since AngularJS as an alternative to direct injector calls. In Angular 1, it was necessary to bootstrap a test with ngMock . It is entirely optional in Angular 2 and higher

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

小例题记录(JAVA)~~~~~~输出整数的位数

邮差的信 提交于 2019-12-01 01:56:17
例:写一个函数,接受一个整数,输出这个整数是几位数? 注: / 是取整; %是取余; n%10是求得一个整数的最后一位数; import java.util.*; public class TestWeiShu{ public static void main(String[] args){ System.out.println("请输入一个整数:"); Scanner sc= new Scanner(System.in); int n=sc.nextInt(); int count=0; while(n!=0){ n=n/10; count++; } System.out.println("这个整数共有:"+count+"位"); } } 来源: CSDN 作者: tea_jasmine 链接: https://blog.csdn.net/tea_jasmine/article/details/83901080

Argument 'fn' is not a function, when trying to do unit test with Jasmine and AngularJS

99封情书 提交于 2019-12-01 01:08:07
问题 I'm trying to do some unit tests with Jasmine in my Angular application, but I'm facing some errors. Error Error: [$injector:modulerr] Failed to instantiate module LocalStorageModule due to: Error: [ng:areq] Argument 'fn' is not a function, got string Spec describe("testing the controller", function () { var $controllerConstructor; var scope; beforeEach(module('app', ['ngRoute', 'LocalStorageModule'])); beforeEach(inject(function ($controller, $rootScope) { $controllerConstructor =

Testing backend API via $http in AngularJS/karma/jasmine tests?

末鹿安然 提交于 2019-12-01 01:00:40
问题 How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/<echo>') def echo_echo(echo): response.headers['Access-Control-Allow-Origin'] = '*' return {'echo': echo} # Served as JSON if __name__ == '__main__': run() test/unit/apiSpec.js // Should this be in `test/e2e/apiSpec.js`? describe('echo', function () { var scope, http; beforeEach(inject(function (

Protractor: 'wait' doesn't work with “element.all”

一曲冷凌霜 提交于 2019-12-01 00:06:51
问题 I write Protractor automation tests and faced an issue. Wait command doesn't actually wait for one of the array elements. See the example below: I try to wait for the first element after navigating to webpage. var category = element.all(by.repeater('category in listCtrl.categories')); var category2 = $$('.category-name.custom-tooltip-link.ng-binding'); var EC = protractor.ExpectedConditions; describe('wait for the first category', function() { it('wait', function() { browser.get('http://www

Protractor: wait method isn't work

心已入冬 提交于 2019-11-30 23:23:57
I try to use wait() method instead sleep(), but it isn't working. I had code: browser.actions().click(filter_field).perform(); browser.sleep(3000); if (baloon_info.isPresent()) { //some expections } else { expect(true).toBe(false); } Now I want to do something like: var present_pri = browser.wait(function () { return balloon_info.isPresent(); }, 3000); if (present_pri) { //some expections } else { expect(true).toBe(false); } But if balloon isn't present I have the error message: Wait timed out after 3117ms instead expected true to be false (present_pri == false) I tryed to write: var EC =