Skip to content

Commit

Permalink
fix: improve scope-enum unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Nov 16, 2023
1 parent 8987b09 commit 8fb26ae
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions @commitlint/rules/src/scope-enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ test('scope-enum with plain message and always should succeed empty enum', async
});

test('scope-enum with plain message and never should error empty enum', async () => {
const [actual] = scopeEnum(await parsed.plain, 'never', []);
const [actual, message] = scopeEnum(await parsed.plain, 'never', []);
const expected = false;
expect(actual).toEqual(expected);
expect(message).toEqual('scope must not be one of []');
});

test('with plain message should succeed correct enum', async () => {
Expand All @@ -36,15 +37,17 @@ test('with plain message should succeed correct enum', async () => {
});

test('scope-enum with plain message should error false enum', async () => {
const [actual] = scopeEnum(await parsed.plain, 'always', ['foo']);
const [actual, message] = scopeEnum(await parsed.plain, 'always', ['foo']);
const expected = false;
expect(actual).toEqual(expected);
expect(message).toEqual('scope must be one of [foo]');
});

test('scope-enum with plain message should error forbidden enum', async () => {
const [actual] = scopeEnum(await parsed.plain, 'never', ['bar']);
const [actual, message] = scopeEnum(await parsed.plain, 'never', ['bar']);
const expected = false;
expect(actual).toEqual(expected);
expect(message).toEqual('scope must not be one of [bar]');
});

test('scope-enum with plain message should succeed forbidden enum', async () => {
Expand Down Expand Up @@ -97,18 +100,27 @@ test('scope-enum with empty scope and never should succeed empty enum', async ()

test('scope-enum with multiple scopes should succeed on message with multiple scopes', async () => {
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'baz']);
const expected = false;
const expected = true;
expect(actual).toEqual(expected);
});

test('scope-enum with multiple scopes should succeed on message with forbidden enum', async () => {
const [actual, message] = scopeEnum(await parsed.multiple, 'never', [
'bar',
'qux',
]);
const expected = true;
expect(actual).toEqual(expected);
});

test('scope-enum with multiple scopes should error on message with forbidden enum', async () => {
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'qux']);
test('scope-enum with multiple scope should succeed on message with superfluous scope', async () => {
const [actual, message] = scopeEnum(await parsed.multiple, 'never', ['bar']);
const expected = true;
expect(actual).toEqual(expected);
});

test('scope-enum with multiple scopes should error on message with superfluous scope', async () => {
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar']);
test('scope-enum with multiple scope should succeed on message with multiple scopes', async () => {
const [actual] = scopeEnum(await parsed.multiple, 'always', ['bar', 'baz']);
const expected = true;
expect(actual).toEqual(expected);
});
Expand Down

0 comments on commit 8fb26ae

Please sign in to comment.