Skip to content

Commit

Permalink
test: refactor tests of isInCurrentMonth
Browse files Browse the repository at this point in the history
fix: fix .toMatchInlineSnapshot throws uncaught error

Signed-off-by: Rong Sen Ng (motss) <[email protected]>
  • Loading branch information
motss committed Jan 6, 2024
1 parent 7492ac4 commit ac2fba2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/helpers/clamp-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ describe(clampValue.name, () => {
}) => {
const result = clampValue(min, max, value);

expect(result).equal($_value);
expect(result).toBe($_value);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/helpers/date-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe(dateValidator.name, () => {
}) => {
const result = dateValidator(value, defaultDate);

expect(result).deep.equal($_value);
expect(result).toEqual($_value);
});

});
8 changes: 6 additions & 2 deletions src/__tests__/helpers/focus-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe(focusElement.name, () => {

const focusedElement = await focusElement(Promise.resolve(el));

expect(document.activeElement).toMatchInlineSnapshot(focusedElement);
expect(focusedElement.outerHTML).toBe('<button>Focus me</button>');
// fixme: learn more at https://github.com/vitest-dev/vitest/issues/2327
// expect(document.activeElement).toMatchInlineSnapshot(focusedElement);
});

it('focuses element with optional callback', async () => {
Expand All @@ -21,7 +23,9 @@ describe(focusElement.name, () => {
}));
});

expect(document.activeElement).toMatchInlineSnapshot(focusedElement);
expect(focusedElement.outerHTML).toBe('<button>Focus me</button>');
// fixme: learn more at https://github.com/vitest-dev/vitest/issues/2327
// expect(focusedElement.outerHTML).toMatchInlineSnapshot('"<button>Focus me</button>"');
});

});
52 changes: 23 additions & 29 deletions src/__tests__/helpers/is-in-current-month.test.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import { expect } from '@open-wc/testing';
import { describe, expect, it } from 'vitest';

import { isInCurrentMonth } from '../../helpers/is-in-current-month';
import { messageFormatter } from '../test-utils/message-formatter';

describe(isInCurrentMonth.name, () => {
type CaseIsInCurrentMonth = [
target: Date,
source: Date,
expected: boolean
];
const casesIsInCurrentMonth: CaseIsInCurrentMonth[] = [
[
new Date('2020-02-02'),
new Date('2020-02-12'),
true,
],
[
new Date('2020-02-02'),
new Date('2020-03-12'),
false,
],
];
casesIsInCurrentMonth.forEach(a => {
const [testTarget, testSource, expected] = a;
it.each<{
$_value: boolean;
source: Date;
target: Date;
}>([
{
$_value: true,
source: new Date('2020-02-12'),
target: new Date('2020-02-02'),
},
{
$_value: false,
source: new Date('2020-03-12'),
target: new Date('2020-02-02'),
},
])('returns if $target is current month of $source', ({
$_value,
source,
target,
}) => {
const result = isInCurrentMonth(target, source);

it(
messageFormatter('returns if %s is current month of %s', a),
() => {
const result = isInCurrentMonth(testTarget, testSource);

expect(result).equal(expected);
}
);
expect(result).toBe($_value);
});

});

0 comments on commit ac2fba2

Please sign in to comment.