Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Testing module for @ngrx/store #1027

Merged
merged 7 commits into from
Oct 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feature: Testing module for @ngrx/store
TeoTN authored and piotrstaniow committed Oct 10, 2018
commit 380ef4898d87e6bd0590b362e057c331d063684e
2 changes: 2 additions & 0 deletions modules/store/BUILD
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ ng_package(
name = "npm_package",
srcs = glob(["**/*.externs.js"]) + [
"package.json",
"//modules/store/testing:package.json",
],
entry_point = "modules/store/index.js",
packages = [
@@ -25,5 +26,6 @@ ng_package(
],
deps = [
":store",
"//modules/store/testing",
],
)
19 changes: 19 additions & 0 deletions modules/store/testing/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package(default_visibility = ["//visibility:public"])

exports_files(["package.json"])

load("//tools:defaults.bzl", "ng_module")

ng_module(
name = "testing",
srcs = glob([
"*.ts",
"src/**/*.ts",
]),
module_name = "@ngrx/store/testing",
visibility = ["//visibility:public"],
deps = [
"//modules/store",
"@rxjs",
],
)
1 change: 1 addition & 0 deletions modules/store/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/testing';
brandonroberts marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions modules/store/testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@ngrx/store/testing",
"typings": "./testing.d.ts",
"main": "../bundles/core-testing.umd.js",
"module": "../fesm5/testing.js",
"es2015": "../fesm2015/testing.js",
"esm5": "../esm5/testing/testing.js",
"esm2015": "../esm2015/testing/testing.js",
"fesm5": "../fesm5/testing.js",
"fesm2015": "../fesm2015/testing.js"
}
12 changes: 12 additions & 0 deletions modules/store/testing/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
entry: './dist/store/@ngrx/store/testing.es5.js',
dest: './dist/store/bundles/store-testing.umd.js',
format: 'umd',
exports: 'named',
moduleName: 'ngrx.store.testing',
globals: {
'@angular/core': 'ng.core',
'@ngrx/store': 'ngrx.store',
'rxjs': 'Rx',
}
}
31 changes: 31 additions & 0 deletions modules/store/testing/src/testing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
StateObservable,
Store,
ReducerManager,
ActionsSubject,
} from '@ngrx/store';
import { BehaviorSubject } from 'rxjs';

export class MockStore<T> extends Store<T> {
private stateSubject = new BehaviorSubject<T>({} as T);

constructor(
state$: StateObservable,
actionsObserver: ActionsSubject,
reducerManager: ReducerManager
) {
super(state$, actionsObserver, reducerManager);
this.source = this.stateSubject.asObservable();
}

nextMock(nextState: T) {
this.stateSubject.next(nextState);
}
}

export function provideMockStore() {
return {
provide: Store,
useClass: MockStore,
};
}
13 changes: 13 additions & 0 deletions modules/store/testing/tsconfig-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig-build",
"compilerOptions": {
"paths": {
"@ngrx/store": ["../../dist/packages/store"]
}
},
"files": ["index.ts"],
"angularCompilerOptions": {
// Work around for issue: https://github.com/angular/angular/issues/22210
"strictMetadataEmit": false
}
}