Skip to content

Commit f0cbdde

Browse files
feat(DateAssertion): show DateAssertion error messages in ISO format (#40)
* feat: show DateAssertion error messages in ISO format * Fixed line length in test file * fix: removed new lines form strings in test file * improvement to line length * Update @ChristianSama as a contributor Co-authored-by: Christian <[email protected]>
1 parent 6d6045f commit f0cbdde

File tree

6 files changed

+200
-23
lines changed

6 files changed

+200
-23
lines changed

.all-contributorsrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
"avatar_url": "https://avatars.githubusercontent.com/u/43491324?v=4",
7171
"profile": "https://github.com/ChristianSama",
7272
"contributions": [
73-
"doc"
73+
"doc",
74+
"code",
75+
"test"
7476
]
7577
}
7678
],

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
5151
<td align="center"><a href="https://github.com/alejo0o"><img src="https://avatars.githubusercontent.com/u/60680371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alejandro Vivanco</b></sub></a><br /><a href="https://github.com/stackbuilders/assertive-ts/commits?author=alejo0o" title="Code">💻</a> <a href="https://github.com/stackbuilders/assertive-ts/commits?author=alejo0o" title="Tests">⚠️</a></td>
5252
<td align="center"><a href="https://github.com/dalejo96"><img src="https://avatars.githubusercontent.com/u/77456654?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Villamarin</b></sub></a><br /><a href="https://github.com/stackbuilders/assertive-ts/commits?author=dalejo96" title="Code">💻</a> <a href="https://github.com/stackbuilders/assertive-ts/commits?author=dalejo96" title="Tests">⚠️</a></td>
5353
<td align="center"><a href="https://github.com/Alex0jk"><img src="https://avatars.githubusercontent.com/u/22301755?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexander Mejía</b></sub></a><br /><a href="https://github.com/stackbuilders/assertive-ts/commits?author=Alex0jk" title="Code">💻</a> <a href="https://github.com/stackbuilders/assertive-ts/commits?author=Alex0jk" title="Tests">⚠️</a></td>
54-
<td align="center"><a href="https://github.com/ChristianSama"><img src="https://avatars.githubusercontent.com/u/43491324?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christian Samaniego</b></sub></a><br /><a href="https://github.com/stackbuilders/assertive-ts/commits?author=ChristianSama" title="Documentation">📖</a></td>
54+
<td align="center"><a href="https://github.com/ChristianSama"><img src="https://avatars.githubusercontent.com/u/43491324?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christian Samaniego</b></sub></a><br /><a href="https://github.com/stackbuilders/assertive-ts/commits?author=ChristianSama" title="Documentation">📖</a> <a href="https://github.com/stackbuilders/assertive-ts/commits?author=ChristianSama" title="Code">💻</a> <a href="https://github.com/stackbuilders/assertive-ts/commits?author=ChristianSama" title="Tests">⚠️</a></td>
5555
</tr>
5656
</table>
5757

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"lint": "tslint -c tslint.json \"!(build|dist)/**/*.ts\"",
1818
"test": "cross-env NODE_ENV=test TS_NODE_TRANSPILE_ONLY=true mocha"
1919
},
20+
"dependencies": {
21+
"@cometlib/dedent": "^0.8.0-es.10"
22+
},
2023
"devDependencies": {
2124
"@types/mocha": "^9.1.0",
2225
"@types/node": "^17.0.15",

src/lib/DateAssertion.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export class DateAssertion extends Assertion<Date> {
6969
const error = new AssertionError({
7070
actual: this.actual,
7171
expected: options,
72-
message: `Expected <${this.actual}> to be equal to <${optionsAsDate}>`
72+
message: `Expected <${this.actual.toISOString()}> to be equal to <${optionsAsDate.toISOString()}>`
7373
});
7474
const invertedError = new AssertionError({
7575
actual: this.actual,
76-
message: `Expected <${this.actual}> NOT to be equal to <${optionsAsDate}>`
76+
message: `Expected <${this.actual.toISOString()}> NOT to be equal to <${optionsAsDate.toISOString()}>`
7777
});
7878

7979
return this.execute({
@@ -93,11 +93,11 @@ export class DateAssertion extends Assertion<Date> {
9393
const error = new AssertionError({
9494
actual: this.actual,
9595
expected: date,
96-
message: `Expected <${this.actual}> to be before <${date}>`
96+
message: `Expected <${this.actual.toISOString()}> to be before <${date.toISOString()}>`
9797
});
9898
const invertedError = new AssertionError({
9999
actual: this.actual,
100-
message: `Expected <${this.actual}> NOT to be before <${date}>`
100+
message: `Expected <${this.actual.toISOString()}> NOT to be before <${date.toISOString()}>`
101101
});
102102

103103
return this.execute({
@@ -116,11 +116,11 @@ export class DateAssertion extends Assertion<Date> {
116116
public toBeBeforeOrEqual(date: Date): this {
117117
const error = new AssertionError({
118118
actual: this.actual,
119-
message: `Expected <${this.actual}> to be before or equal to <${date}>`
119+
message: `Expected <${this.actual.toISOString()}> to be before or equal to <${date.toISOString()}>`
120120
});
121121
const invertedError = new AssertionError({
122122
actual: this.actual,
123-
message: `Expected <${this.actual}> NOT to be before or equal to <${date}>`
123+
message: `Expected <${this.actual.toISOString()}> NOT to be before or equal to <${date.toISOString()}>`
124124
});
125125

126126
return this.execute({
@@ -139,11 +139,11 @@ export class DateAssertion extends Assertion<Date> {
139139
public toBeAfter(date: Date): this {
140140
const error = new AssertionError({
141141
actual: this.actual,
142-
message: `Expected <${this.actual}> to be after <${date}>`
142+
message: `Expected <${this.actual.toISOString()}> to be after <${date.toISOString()}>`
143143
});
144144
const invertedError = new AssertionError({
145145
actual: this.actual,
146-
message: `Expected <${this.actual}> NOT to be after <${date}>`
146+
message: `Expected <${this.actual.toISOString()}> NOT to be after <${date.toISOString()}>`
147147
});
148148

149149
return this.execute({
@@ -162,11 +162,11 @@ export class DateAssertion extends Assertion<Date> {
162162
public toBeAfterOrEqual(date: Date): this {
163163
const error = new AssertionError({
164164
actual: this.actual,
165-
message: `Expected <${this.actual}> to be after or equal to <${date}>`
165+
message: `Expected <${this.actual.toISOString()}> to be after or equal to <${date.toISOString()}>`
166166
});
167167
const invertedError = new AssertionError({
168168
actual: this.actual,
169-
message: `Expected <${this.actual}> NOT to be after or equal to <${date}>`
169+
message: `Expected <${this.actual.toISOString()}> NOT to be after or equal to <${date.toISOString()}>`
170170
});
171171

172172
return this.execute({

test/lib/DateAssertion.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dedent from "@cometlib/dedent";
12
import assert, { AssertionError } from "assert";
23

34
import { DateAssertion } from "../../src/lib/DateAssertion";
@@ -46,7 +47,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
4647
const test = new DateAssertion(actualDate);
4748
assert.deepStrictEqual(test.toMatchDateParts(options), test);
4849
assert.throws(() => test.not.toMatchDateParts(options), {
49-
message: `Expected <${actualDate}> NOT to be equal to <${dateOptionsToDate(options)}>`,
50+
message: `Expected <${actualDate.toISOString()}> NOT to be equal to <${dateOptionsToDate(options).toISOString()}>`,
5051
name: AssertionError.name
5152
});
5253
});
@@ -66,7 +67,10 @@ describe("[Unit] DateAssertion.test.ts", () => {
6667
};
6768
const test = new DateAssertion(actualDate);
6869
assert.throws(() => test.toMatchDateParts(options), {
69-
message: `Expected <${actualDate}> to be equal to <${dateOptionsToDate(options)}>`,
70+
message: dedent`
71+
Expected <${actualDate.toISOString()}> to be equal to \
72+
<${dateOptionsToDate(options).toISOString()}>
73+
`,
7074
name: AssertionError.name
7175
});
7276
assert.deepStrictEqual(test.not.toMatchDateParts(options), test);
@@ -82,7 +86,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
8286
const test = new DateAssertion(actualDate);
8387
assert.deepStrictEqual(test.toBeBefore(passedDate), test);
8488
assert.throws(() => test.not.toBeBefore(passedDate), {
85-
message: `Expected <${actualDate}> NOT to be before <${passedDate}>`,
89+
message: `Expected <${actualDate.toISOString()}> NOT to be before <${passedDate.toISOString()}>`,
8690
name: AssertionError.name
8791
});
8892
});
@@ -94,7 +98,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
9498
const passedDate = new Date(2021, 1, 1);
9599
const test = new DateAssertion(actualDate);
96100
assert.throws(() => test.toBeBefore(passedDate), {
97-
message: `Expected <${actualDate}> to be before <${passedDate}>`,
101+
message: `Expected <${actualDate.toISOString()}> to be before <${passedDate.toISOString()}>`,
98102
name: AssertionError.name
99103
});
100104
assert.deepStrictEqual(test.not.toBeBefore(passedDate), test);
@@ -110,7 +114,10 @@ describe("[Unit] DateAssertion.test.ts", () => {
110114
const test = new DateAssertion(actualDate);
111115
assert.deepStrictEqual(test.toBeBeforeOrEqual(passedDate), test);
112116
assert.throws(() => test.not.toBeBeforeOrEqual(passedDate), {
113-
message: `Expected <${actualDate}> NOT to be before or equal to <${passedDate}>`,
117+
message: dedent`
118+
Expected <${actualDate.toISOString()}> \
119+
NOT to be before or equal to <${passedDate.toISOString()}>
120+
`,
114121
name: AssertionError.name
115122
});
116123
});
@@ -123,7 +130,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
123130
const passedDate = new Date(2021, 1, 1);
124131
const test = new DateAssertion(actualDate);
125132
assert.throws(() => test.toBeBeforeOrEqual(passedDate), {
126-
message: `Expected <${actualDate}> to be before or equal to <${passedDate}>`,
133+
message: `Expected <${actualDate.toISOString()}> to be before or equal to <${passedDate.toISOString()}>`,
127134
name: AssertionError.name
128135
});
129136
assert.deepStrictEqual(
@@ -143,7 +150,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
143150
const test = new DateAssertion(actualDate);
144151
assert.deepStrictEqual(test.toBeAfter(passedDate), test);
145152
assert.throws(() => test.not.toBeAfter(passedDate), {
146-
message: `Expected <${actualDate}> NOT to be after <${passedDate}>`,
153+
message: `Expected <${actualDate.toISOString()}> NOT to be after <${passedDate.toISOString()}>`,
147154
name: AssertionError.name
148155
});
149156
});
@@ -155,7 +162,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
155162
const passedDate = new Date(2021, 2, 1);
156163
const test = new DateAssertion(actualDate);
157164
assert.throws(() => test.toBeAfter(passedDate), {
158-
message: `Expected <${actualDate}> to be after <${passedDate}>`,
165+
message: `Expected <${actualDate.toISOString()}> to be after <${passedDate.toISOString()}>`,
159166
name: AssertionError.name
160167
});
161168
assert.deepStrictEqual(test.not.toBeAfter(passedDate), test);
@@ -171,7 +178,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
171178
const test = new DateAssertion(actualDate);
172179
assert.deepStrictEqual(test.toBeAfterOrEqual(passedDate), test);
173180
assert.throws(() => test.not.toBeAfterOrEqual(passedDate), {
174-
message: `Expected <${actualDate}> NOT to be after or equal to <${passedDate}>`,
181+
message: `Expected <${actualDate.toISOString()}> NOT to be after or equal to <${passedDate.toISOString()}>`,
175182
name: AssertionError.name
176183
});
177184
});
@@ -183,7 +190,7 @@ describe("[Unit] DateAssertion.test.ts", () => {
183190
const passedDate = new Date(2021, 2, 1);
184191
const test = new DateAssertion(actualDate);
185192
assert.throws(() => test.toBeAfterOrEqual(passedDate), {
186-
message: `Expected <${actualDate}> to be after or equal to <${passedDate}>`,
193+
message: `Expected <${actualDate.toISOString()}> to be after or equal to <${passedDate.toISOString()}>`,
187194
name: AssertionError.name
188195
});
189196
assert.deepStrictEqual(test.not.toBeAfterOrEqual(passedDate), test);

0 commit comments

Comments
 (0)