Skip to content

Commit 93619c8

Browse files
committed
added test and fixed linter warnings
1 parent 576a0c0 commit 93619c8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/types/VariableType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class VariableType {
22
constructor(public value: string) {}
3-
3+
44
toJSON() {
55
return `$${this.value}`;
66
}

src/types/__tests__/VariableType.tests.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,36 @@ describe('VariableType()', () => {
4343
}`);
4444
});
4545

46+
it('properly ads dollar sign on JSON.stringify', () => {
47+
const query = {
48+
query: {
49+
__variables: {
50+
someString: 'String!',
51+
varWithDefault: 'String = "default_value"'
52+
},
53+
Posts: {
54+
__args: {
55+
arg1: 20,
56+
arg2: new VariableType('someString')
57+
},
58+
id: true,
59+
title: true,
60+
comments: {
61+
__args: {
62+
offensiveOnly: true
63+
},
64+
id: true,
65+
comment: true,
66+
user: true
67+
}
68+
}
69+
}
70+
};
71+
expect(JSON.stringify(query)).to.equal(
72+
'{"query":{"__variables":{"someString":"String!","varWithDefault":"String = \\"default_value\\""},'
73+
+ '"Posts":{"__args":{"arg1":20,"arg2":"$someString"},"id":true,"title":true,"comments":'
74+
+ '{"__args":{"offensiveOnly":true},"id":true,"comment":true,"user":true}}}}'
75+
);
76+
});
77+
4678
});

0 commit comments

Comments
 (0)