jasmine

Some of your tests did a full page reload - error when running Jasmine tests

白昼怎懂夜的黑 提交于 2019-12-03 00:58:54
I'm running into an issue where when I run my tests on Jasmine, I get this error below. The problem is, it seems to happen when I try to execute a certain amount of tests. It doesn't seem to be tied to a particular test, as if I comment out some, the tests pass. If I uncomment some tests, the error appears. If I comment out ones that were uncommented before, they all pass again. (ie if I have red, green, blue and orange test and it fails, I comment out orange and blue it passes, then I uncomment blue and orange it fails again, but if I comment out red and green it passes again). Chrome 41.0

AngularJS Promise Callback Not Trigged in JasmineJS Test

你。 提交于 2019-12-03 00:57:56
Problem Intro I'm trying to unit test an AngularJS service that wraps the Facebook JavaScript SDK FB object; however, the test isn't working, and I haven't been able to figure out why. Also, the service code does work when I run it in a browser instead of a JasmineJS unit test, run with Karma test runner . I'm testing an asynchronous method using Angular promises via the $q object. I have the tests set up to run asynchronously using the Jasmine 1.3.1 async testing methods , but the waitsFor() function never returns true (see test code below), it just times-out after 5 seconds . (Karma doesn't

Should I use ES6 import or reference path when loading Typescript definition file?

匿名 (未验证) 提交于 2019-12-03 00:53:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Would it be preferred to use ES6 import or reference path comment when loading Typescript (1.6 above) definition files? import {describe, it, expect, jasmine} from './jasmine' or import * as jasmine from './jasmine' vs. ///<reference path="jasmine.d.ts"/> 回答1: @Yudhistira Arya, as you can see from @ahejlsberg ES6 Modules #2242 post It is recommended that TypeScript libraries and applications be updated to use the new syntax, but this is not a requirement. The new ES6 module syntax coexists with TypeScript's original internal and external

Chutzpah and Jasmine 2.0 and RequrieJs

匿名 (未验证) 提交于 2019-12-03 00:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having some bother getting Chutzpah to work with requireJs/jasmine 2.0. This method worked for version 1.3 but now for jasmine version 2.0 chutzpah has stopped picking up the tests. I upgraded chutzpah to 3.1.1 for the jasmine 2.0 support as well. I did have to make a small change to load jasmine from requireJs to make it work but I figured this shouldn't affect chutzpah as it was just loading the html. Here's the command I run for chutzpah. chutzpah.console.exe path/to/SpecRunner.html The console now fails to pick up tests === 0 total,

angular2单元测试学习

匿名 (未验证) 提交于 2019-12-03 00:13:02
单元测试简介:https://segmentfault.com/a/1190000009737186 单元测试-Jasmine:https://segmentfault.com/a/1190000009737204 angular2单元测试:https://segmentfault.com/a/1190000009769787#articleHeader1 概念简介 Jasmine Jasmine测试框架提供了编写测试脚本的工具集,而且非常优秀的语义化,让测试代码看起来像是在读一段话。 describe,beforeEach,it,expect等方法,利用这些方法可以定义单元测试如何执行,单元测试的结果和预期。 官方文档:https://jasmine.github.io/api/edge/global.html#expect Karma 有Jasmine测试脚本,还需要Karma来帮忙管理这些脚本,以便于在浏览器中运行,可以理解Karma为运行这些测试脚本的容器。 需要在根目录创建 karma.conf.js 文件,这相当于一些约定。文件是为了告知karma需要启用哪些插件、加载哪些测试脚本、需要哪些测试浏览器环境、测试报告通知方式、日志等等。 官方文档:https://karma-runner.github.io/1.0/config/configuration-file

How to mock Angular 4.3 httpClient an error response in testing

空扰寡人 提交于 2019-12-03 00:01:43
I have a below interceptor auth-interceptor.service.ts import {Injectable, Injector} from '@angular/core'; import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs/Observable'; import {Cookie} from './cookie.service'; import {Router} from '@angular/router'; import {UserService} from './user.service'; import {ToasterService} from '../toaster/toaster.service'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor

jasmine 2.0 test with a custom matcher fails: undefined is not a function

十年热恋 提交于 2019-12-02 23:54:27
I have this function in my source file: function gimmeANumber(){ var x = 4; return x; } And a spec borrowed from this tutorial describe('Hello world', function() { beforeEach(function() { this.addMatchers({ toBeDivisibleByTwo: function() { return (this.actual % 2) === 0; } }); }); it('is divisible by 2', function() { expect(gimmeANumber()).toBeDivisibleByTwo(); }); }); This is the error: TypeError: undefined is not a function at Object. (file:///home/n/foo/jasmine/jasmine-2.0.0/dist/spec/HelloWorldSpec.js...) Thank you. The API for adding custom matchers has changed since 1.3. You can see the

AngularJS Protractor - Finding an Element on a Page Using Ng-Click Binding

寵の児 提交于 2019-12-02 23:25:14
I have a button on a page that looks like: <button ng-click="myFunction()" ng-show="flag"> Submit </button> The element has no ID. Is there a way to find this element using the function bound to Ng-Click? Or do I have to assign an ID to this element to locate it using Jasmine / Protractor? Just tested this and it works: element(by.css('[ng-click="myFunction()"]')) I went through the Protractor API and didn't find anything related to finding an element through ng-click . I did find element(by.buttonText("Submit")); Not quite the same, but does the job in my environment. Nguyen Vu Hoang If you

Angular单元测试与E2E测试

匿名 (未验证) 提交于 2019-12-02 23:03:14
本文介绍了Angular单元测试和E2E测试的配置与测试方法。示例APP使用Angular 7 CLI创建,已配置好基础测试环境,生成了测试样例代码。默认,Angular单元测试使用Jasmine测试框架和Karma测试运行器,E2E测试使用Jasmine测试框架和Protractor端到端测试框架。 配置单元测试 Jasmine是一个用于测试JavaScript的行为驱动开发框架,不依赖于任何其他JavaScript框架。 Karma是测试运行器,为开发人员提供了高效、真实的测试环境,支持多种浏览器,易于调试。 配置文件 单元测试配置文件test.ts和karma.conf.js: test.ts import 'zone.js/dist/zone-testing'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; declare const require: any; // First, initialize the Angular testing environment.

Protractor flakiness

邮差的信 提交于 2019-12-02 22:19:56
I maintain a complex Angular (1.5.x) application that is being E2E tested using Protractor (2.5.x). I am experiencing a problem with this approach, which presents primarily in the way the tests seem flaky. Tests that worked perfectly well in one pull request fail in another. This concerns simple locators, such as by.linkTest(...). I debugged the failing tests and the app is on the correct page, the links are present and accessible. Has anyone else experienced these consistency problems? Knows of a cause or workaround? alecxe Just Say No to More End-to-End Tests! That said, here are the few