Skip to content

Commit 8bfdaf7

Browse files
committed
Port @ngrx/entity tests
1 parent fc3e33b commit 8bfdaf7

File tree

6 files changed

+977
-0
lines changed

6 files changed

+977
-0
lines changed

src/entities/entity_state.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { createEntityAdapter, EntityAdapter } from './index'
2+
import { BookModel } from './fixtures/book'
3+
4+
describe('Entity State', () => {
5+
let adapter: EntityAdapter<BookModel>
6+
7+
beforeEach(() => {
8+
adapter = createEntityAdapter({
9+
selectId: (book: BookModel) => book.id
10+
})
11+
})
12+
13+
it('should let you get the initial state', () => {
14+
const initialState = adapter.getInitialState()
15+
16+
expect(initialState).toEqual({
17+
ids: [],
18+
entities: {}
19+
})
20+
})
21+
22+
it('should let you provide additional initial state properties', () => {
23+
const additionalProperties = { isHydrated: true }
24+
25+
const initialState = adapter.getInitialState(additionalProperties)
26+
27+
expect(initialState).toEqual({
28+
...additionalProperties,
29+
ids: [],
30+
entities: {}
31+
})
32+
})
33+
})

src/entities/fixtures/book.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface BookModel {
2+
id: string
3+
title: string
4+
}
5+
6+
export const AClockworkOrange: BookModel = Object.freeze({
7+
id: 'aco',
8+
title: 'A Clockwork Orange'
9+
})
10+
11+
export const AnimalFarm: BookModel = Object.freeze({
12+
id: 'af',
13+
title: 'Animal Farm'
14+
})
15+
16+
export const TheGreatGatsby: BookModel = Object.freeze({
17+
id: 'tgg',
18+
title: 'The Great Gatsby'
19+
})

0 commit comments

Comments
 (0)