Skip to content

Commit

Permalink
(1) upgrade typescript to 3.1.3
Browse files Browse the repository at this point in the history
(2) typescript 2.9 not allow symbol to be used as index. microsoft/TypeScript#1863. Current there is a PR open to address this issue microsoft/TypeScript#26797
  • Loading branch information
tru committed Oct 28, 2018
1 parent d4fe267 commit 7f06b35
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"chai": "^4.1.2",
"mocha": "^3.5.3",
"ts-node": "^6.0.3",
"typescript": "2.8.3",
"typescript": "3.1.3",
"source-map-support": "^0.5.5"
}
}
3 changes: 2 additions & 1 deletion src/CallsDontMatchError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class CallsDontMatchError extends Error {

constructor(expectedCall: ArgumentInvocation, otherInteractions: ArgumentInvocation[], methodName: PropertyKey) {
super();
let message = `${methodName} was not called with: ${expectedCall.prettyPrint()}\n`;

let message = `${String(methodName)} was not called with: ${expectedCall.prettyPrint()}\n`;

if (otherInteractions.length !== 0) {
message = message + ` Other interactions with this mock: [${ prettyPrintOtherInteractions(otherInteractions)}]`;
Expand Down
22 changes: 11 additions & 11 deletions src/StubbedActionMatcherRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StubbedActionMatcherRepo {

recordAndFindMatch(propertyKey: PropertyKey, argsToMatch: ArgumentInvocation): LookupResult {
this.recordCall(propertyKey, argsToMatch);
const stubbedActionMatchers = this.stubbedActionMatcherMap[propertyKey] || [];
const stubbedActionMatchers = this.stubbedActionMatcherMap[String(propertyKey)] || [];

const [lastMatchedMatcher] =
stubbedActionMatchers
Expand All @@ -36,31 +36,31 @@ export class StubbedActionMatcherRepo {
}

private setStubbedActionMatcher(propertyKey: PropertyKey, stubbedActionMatcher: StubbedActionMatcher) {
if (!this.stubbedActionMatcherMap[propertyKey])
this.stubbedActionMatcherMap[propertyKey] = [];
if (!this.stubbedActionMatcherMap[String(propertyKey)])
this.stubbedActionMatcherMap[String(propertyKey)] = [];

this.stubbedActionMatcherMap[propertyKey].push(stubbedActionMatcher);
this.stubbedActionMatcherMap[String(propertyKey)].push(stubbedActionMatcher);
}

lookupCalls(propertyKey: PropertyKey): ArgumentInvocation[] {
return this.callMap[propertyKey] || [];
return this.callMap[String(propertyKey)] || [];
}

private recordCall(propertyKey: PropertyKey, argsToMatch: ArgumentInvocation) {
this.callMap[propertyKey] = (this.callMap[propertyKey] || []);
this.callMap[String(propertyKey)] = (this.callMap[String(propertyKey)] || []);

this.callMap[propertyKey].push(argsToMatch)
this.callMap[String(propertyKey)].push(argsToMatch)
}

resetPropertyKey(propertyKey: PropertyKey) {
this.stubbedActionMatcherMap[propertyKey] = [];
this.callMap[propertyKey] = [];
this.stubbedActionMatcherMap[String(propertyKey)] = [];
this.callMap[String(propertyKey)] = [];
}

private deleteCallRecord(propertyKey: PropertyKey, argumentInvocation: ArgumentInvocation) {
this.callMap[propertyKey] = (this.callMap[propertyKey] || []);
this.callMap[String(propertyKey)] = (this.callMap[String(propertyKey)] || []);

this.callMap[propertyKey] = this.callMap[propertyKey].filter((call) => !call.equivalentTo(argumentInvocation))
this.callMap[String(propertyKey)] = this.callMap[String(propertyKey)].filter((call) => !call.equivalentTo(argumentInvocation))

}
}
10 changes: 5 additions & 5 deletions src/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Verifier {
const calls = this.repo.lookupCalls(this.propertyKey);

if (calls.length === 0)
throw new Error(`${this.propertyKey} was never called`)
throw new Error(`${String(this.propertyKey)} was never called`)
}

//noinspection JSUnusedGlobalSymbols
Expand Down Expand Up @@ -49,7 +49,7 @@ class NeverVerifier {
const calls = this.repo.lookupCalls(this.propertyKey);

if (calls.length !== 0)
throw new Error(`${this.propertyKey} was called ${calls.length} times`)
throw new Error(`${String(this.propertyKey)} was called ${calls.length} times`)
}

//noinspection JSUnusedGlobalSymbols
Expand All @@ -62,7 +62,7 @@ class NeverVerifier {
.filter(expectedCall => expectedArgumentInvocation.equivalentTo(expectedCall));

if (callsWithMatchingArgs.length !== 0) {
throw new Error(`${this.propertyKey} was called ${callsWithMatchingArgs.length} times with ${expectedArgumentInvocation.prettyPrint()}`);
throw new Error(`${String(this.propertyKey)} was called ${callsWithMatchingArgs.length} times with ${expectedArgumentInvocation.prettyPrint()}`);
}
}

Expand All @@ -80,7 +80,7 @@ class TimesVerifier {
const calls = this.repo.lookupCalls(this.propertyKey);

if (calls.length !== this.count)
throw new Error(`${this.propertyKey} was was expected to be called ${this.count} times, but was called ${calls.length}`)
throw new Error(`${String(this.propertyKey)} was was expected to be called ${this.count} times, but was called ${calls.length}`)
}

//noinspection JSUnusedGlobalSymbols
Expand All @@ -93,7 +93,7 @@ class TimesVerifier {
.filter(expectedCall => expectedArgumentInvocation.equivalentTo(expectedCall));

if (callsWithMatchingArgs.length !== this.count) {
throw new Error(`${this.propertyKey} was called ${callsWithMatchingArgs.length} times with ${expectedArgumentInvocation.prettyPrint()} but was expected to be called ${this.count} times.`);
throw new Error(`${String(this.propertyKey)} was called ${callsWithMatchingArgs.length} times with ${expectedArgumentInvocation.prettyPrint()} but was expected to be called ${this.count} times.`);
}
}
}

0 comments on commit 7f06b35

Please sign in to comment.