Skip to content

Commit 638dcee

Browse files
tmeasdaySashko Stubailo
authored andcommitted
Made the subscriber test fail when you unsubscribe
1 parent 3cd30fc commit 638dcee

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

test/QueryManager.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,12 @@ describe('QueryManager', () => {
562562
},
563563
};
564564

565+
const data3 = {
566+
people_one: {
567+
name: 'Luke Skywalker has another name',
568+
},
569+
};
570+
565571
const queryManager = mockRefetch({
566572
request,
567573
firstResult: { data: data1 },
@@ -574,7 +580,7 @@ describe('QueryManager', () => {
574580
.then(() => {
575581
const handle = queryManager.watchQuery(request);
576582
let subOneCount: Number;
577-
subscribeAndCount(done, handle, (count, result) => {
583+
const subOne = subscribeAndCount(done, handle, (count, result) => {
578584
subOneCount = count;
579585
if (subOneCount === 1) {
580586
assert.deepEqual(result.data, data1);
@@ -585,18 +591,26 @@ describe('QueryManager', () => {
585591

586592
subscribeAndCount(done, handle, (subTwoCount, result) => {
587593
if (subTwoCount === 1) {
588-
assert.deepEqual(result.data, data1);
589-
handle.refetch();
590-
} else if (subTwoCount === 2) {
591-
assert.deepEqual(result.data, data2);
592-
setTimeout(() => {
593-
try {
594-
assert.equal(subOneCount, 2);
595-
assert.equal(subTwoCount, 2);
596-
done();
597-
} catch (e) { done(e); }
598-
}, 0);
599-
}
594+
assert.deepEqual(result.data, data1);
595+
handle.refetch();
596+
} else if (subTwoCount === 2) {
597+
assert.deepEqual(result.data, data2);
598+
setTimeout(() => {
599+
try {
600+
assert.equal(subOneCount, 2);
601+
602+
subOne.unsubscribe();
603+
handle.refetch();
604+
} catch (e) { done(e); }
605+
}, 0);
606+
} else if (subTwoCount === 3) {
607+
setTimeout(() => {
608+
try {
609+
assert.equal(subOneCount, 2);
610+
done();
611+
} catch (e) { done(e); }
612+
}, 0);
613+
}
600614
});
601615
});
602616
});
@@ -3025,7 +3039,7 @@ describe('QueryManager', () => {
30253039

30263040
client = new ApolloClient({
30273041
networkInterface,
3028-
resultTransformer(result) {
3042+
resultTransformer(result: GraphQLResult) {
30293043
transformCount++;
30303044
return {
30313045
data: assign({}, result.data, {transformCount}),
@@ -3038,7 +3052,7 @@ describe('QueryManager', () => {
30383052
it('transforms query() results', () => {
30393053
response = {data: {foo: 123}};
30403054
return client.query({query: gql`{ foo }`})
3041-
.then((result) => {
3055+
.then((result: GraphQLResult) => {
30423056
assert.deepEqual(result.data, {foo: 123, transformCount: 1});
30433057
});
30443058
});
@@ -3079,7 +3093,7 @@ describe('QueryManager', () => {
30793093
it('transforms mutate() results', () => {
30803094
response = {data: {foo: 123}};
30813095
return client.mutate({mutation: gql`mutation makeChanges { foo }`})
3082-
.then((result) => {
3096+
.then((result: GraphQLResult) => {
30833097
assert.deepEqual(result.data, {foo: 123, transformCount: 1});
30843098
});
30853099
});
@@ -3102,11 +3116,11 @@ describe('QueryManager', () => {
31023116

31033117
client = new ApolloClient({
31043118
networkInterface,
3105-
resultTransformer(result) {
3119+
resultTransformer(result: ApolloQueryResult) {
31063120
result.data.__proto__ = Model.prototype;
31073121
return result;
31083122
},
3109-
resultComparator(result1, result2) {
3123+
resultComparator(result1: GraphQLResult, result2: GraphQLResult) {
31103124
// A real example would, say, deep compare the two while ignoring prototypes.
31113125
const foo1 = result1 && result1.data && result1.data.foo;
31123126
const foo2 = result2 && result2.data && result2.data.foo;

0 commit comments

Comments
 (0)