Create a gist now

Instantly share code, notes, and snippets.

@mitsuruog /quick-reference.md Secret
Last active Mar 30, 2016

What would you like to do?
Angular 1 to 2 Quick Reference In unit testing

Angular 1 to 2 Quick Reference In unit testing

Test runner and Testing framework

Test runner and Testing framework

Angualr 1 Angular 2
Karma + Jasmine similar. Angular 2 は内部でJasmineのAPIをOverwrapしているため、最初はKarma + Jasmineで始めたほうが良い

Basic syntax

Angualr 1 Angular 2
Use Jasmine syntax(e.g. describe, it, beforeEach, afterEach ...) similar.

Assertion

Assertion library

Angualr 1 Angular 2
Use Jasmine matchers(e.g. toEqual, toMatch, not, toThrowError ...) similar. Angualr 2 では独自拡張した ngMatcher がある

Spy, Mock Fixture

Spy and mock library

Angualr 1 Angular 2
Use Jasmine features(e.g. spyOn, and.returnValue, and.callFake, and.throwError) similar.

HTTP Mocking

Angualr 1 Angular 2
$httpbackend MockBackend

Create fixture

Angualr 1 Angular 2
$compile TestComponentBuilder

Others

Mobule override

Angualr 1 Angular 2
$provide を利用した上書き beforeEachProviders と provide を利用した上書き

Dependency injection

Angualr 1 Angular 2
angular.mock.injectinject_moduleName_ モジュール名による注入 inject or injectAsync による注入

変更検知

Angualr 1 Angular 2
scope.$digest()を利用してdigest cycleを実行する fixture.detectChanges()を実行してchange detectorで検知する
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment