Skip to content

Commit dc438f9

Browse files
author
Daan van der Kallen
committed
Add more tests
1 parent 45c2d81 commit dc438f9

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

src/__tests__/Store.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ describe('Pagination', () => {
10131013
});
10141014
});
10151015

1016-
describe('Graph parse', () => {
1016+
describe('Linking relations', () => {
10171017
let mock;
10181018
beforeEach(() => {
10191019
mock = new MockAdapter(axios);
@@ -1025,7 +1025,35 @@ describe('Graph parse', () => {
10251025
}
10261026
});
10271027

1028-
test('animals with owner & town', () => {
1028+
test('instantiate', () => {
1029+
new AnimalStore();
1030+
new AnimalStore({ linkRelations: 'tree' });
1031+
new AnimalStore({ linkRelations: 'graph' });
1032+
expect(() => new AnimalStore({ linkRelations: 'foo' })).toThrow(new Error('[mobx-spine] Unknown relation linking method: foo'));
1033+
})
1034+
1035+
test('fetch animals with owner & town as tree', () => {
1036+
mock.onAny().replyOnce(() => [200, animalsGraphData]);
1037+
1038+
const animalStore = new AnimalStore({
1039+
linkRelations: 'tree',
1040+
relations: ['owner.town'],
1041+
});
1042+
1043+
return animalStore.fetch().then(() => {
1044+
expect(animalStore.map('id')).toEqual([1, 2, 3]);
1045+
1046+
expect(animalStore.at(0).owner).not.toBe(animalStore.at(1).owner);
1047+
expect(animalStore.at(0).owner).not.toBe(animalStore.at(2).owner);
1048+
expect(animalStore.at(1).owner).not.toBe(animalStore.at(2).owner);
1049+
1050+
expect(animalStore.at(0).owner.town).not.toBe(animalStore.at(1).owner.town);
1051+
expect(animalStore.at(0).owner.town).not.toBe(animalStore.at(2).owner.town);
1052+
expect(animalStore.at(1).owner.town).not.toBe(animalStore.at(2).owner.town);
1053+
});
1054+
});
1055+
1056+
test('fetch animals with owner & town as graph', () => {
10291057
mock.onAny().replyOnce(() => [200, animalsGraphData]);
10301058

10311059
const animalStore = new AnimalStore({

0 commit comments

Comments
 (0)