Skip to content

Commit f336cdd

Browse files
author
Danny Blue
committed
tweak config and add sample test
1 parent 83be7d6 commit f336cdd

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

.angular-cli.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test": "test.ts",
1111
"main": "src/ngxs.ts",
1212
"polyfills": "polyfills.ts",
13-
"testTsconfig": "./tsconfig.spec.json"
13+
"tsconfig": "tsconfig.spec.json",
14+
"testTsconfig": "tsconfig.spec.json"
1415
}
1516
],
1617
"test": {

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
[*]
55
charset = utf-8
66
indent_style = space
7-
indent_size = 4
7+
indent_size = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

src/spec/action.spec.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { Ngxs } from '../ngxs';
4+
import { NgxsModule } from '../module';
5+
import { Store } from '../store';
6+
import { Mutation } from '../mutation';
7+
18
describe('Action', () => {
2-
it('should world', () => {
3-
expect(true).toBe(true);
9+
let ngxs: Ngxs;
10+
11+
class AddTodo {
12+
constructor(public readonly payload: string) {}
13+
}
14+
15+
@Store({
16+
defaults: []
17+
})
18+
class TodoStore {
19+
@Mutation(AddTodo)
20+
addTodo(state, action: AddTodo) {
21+
return [...state, action.payload];
22+
}
23+
}
24+
25+
beforeEach(() => {
26+
TestBed.configureTestingModule({
27+
imports: [NgxsModule.forRoot([TodoStore])]
28+
});
29+
30+
ngxs = TestBed.get(Ngxs);
31+
});
32+
33+
it('should add a todo', () => {
34+
ngxs.dispatch(new AddTodo('Get Milk'));
35+
36+
ngxs.select(state => state.todo).subscribe(state => {
37+
expect(state.length).toBe(1);
38+
});
439
});
540
});

tsconfig.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": "tsconfig",
4-
"lib": ["es2015", "dom"],
3+
"baseUrl": "./",
54
"module": "commonjs",
6-
"moduleResolution": "node",
7-
"experimentalDecorators": true,
8-
"emitDecoratorMetadata": true,
9-
"declaration": true,
105
"noEmitHelpers": false,
116
"noEmitOnError": false,
12-
"rootDir": "src/",
137
"skipDefaultLibCheck": true,
148
"skipLibCheck": true,
159
"noImplicitAny": false,
16-
"noUnusedLocals": true,
1710
"strict": true,
11+
"noUnusedLocals": true,
1812
"sourceMap": true,
13+
"declaration": false,
14+
"moduleResolution": "node",
15+
"emitDecoratorMetadata": true,
16+
"experimentalDecorators": true,
1917
"target": "es5",
20-
"types": ["jasmine"],
21-
"outDir": "dist"
18+
"lib": ["es2017", "dom"]
2219
},
2320
"include": ["src/**/*"],
2421
"exclude": ["src/spec/**/*"]

tsconfig.spec.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"strictNullChecks": false
4+
"outDir": "./out-tsc/spec",
5+
"module": "commonjs",
6+
"target": "es5",
7+
"types": ["jasmine"]
58
},
69
"files": ["test.ts"],
7-
"include": ["**/*.spec.ts", "**/*.d.ts", "**/*.module.ts"],
10+
"include": ["**/*.spec.ts"],
811
"exclude": []
912
}

0 commit comments

Comments
 (0)