Add extra tests and use toEqual matcher.

Turns out that toMatchObject would allow extra properties through
This commit is contained in:
Josh Dales
2023-03-20 17:23:11 -04:00
parent cc1e02580b
commit d0d3628020
3 changed files with 42 additions and 29 deletions

View File

@@ -90,7 +90,7 @@ describe('toBranchMatchConfig', () => {
it('returns an empty object', () => { it('returns an empty object', () => {
const result = toBranchMatchConfig(config); const result = toBranchMatchConfig(config);
expect(result).toMatchObject({}); expect(result).toEqual({});
}); });
}); });
@@ -99,7 +99,7 @@ describe('toBranchMatchConfig', () => {
it('sets headBranch in the matchConfig', () => { it('sets headBranch in the matchConfig', () => {
const result = toBranchMatchConfig(config); const result = toBranchMatchConfig(config);
expect(result).toMatchObject<BranchMatchConfig>({ expect(result).toEqual<BranchMatchConfig>({
headBranch: ['testing'] headBranch: ['testing']
}); });
}); });
@@ -109,7 +109,7 @@ describe('toBranchMatchConfig', () => {
it('sets headBranch in the matchConfig', () => { it('sets headBranch in the matchConfig', () => {
const result = toBranchMatchConfig(stringConfig); const result = toBranchMatchConfig(stringConfig);
expect(result).toMatchObject<BranchMatchConfig>({ expect(result).toEqual<BranchMatchConfig>({
headBranch: ['testing'] headBranch: ['testing']
}); });
}); });
@@ -120,7 +120,7 @@ describe('toBranchMatchConfig', () => {
const config = {'base-branch': ['testing']}; const config = {'base-branch': ['testing']};
it('sets baseBranch in the matchConfig', () => { it('sets baseBranch in the matchConfig', () => {
const result = toBranchMatchConfig(config); const result = toBranchMatchConfig(config);
expect(result).toMatchObject<BranchMatchConfig>({ expect(result).toEqual<BranchMatchConfig>({
baseBranch: ['testing'] baseBranch: ['testing']
}); });
}); });
@@ -130,7 +130,7 @@ describe('toBranchMatchConfig', () => {
it('sets baseBranch in the matchConfig', () => { it('sets baseBranch in the matchConfig', () => {
const result = toBranchMatchConfig(stringConfig); const result = toBranchMatchConfig(stringConfig);
expect(result).toMatchObject<BranchMatchConfig>({ expect(result).toEqual<BranchMatchConfig>({
baseBranch: ['testing'] baseBranch: ['testing']
}); });
}); });
@@ -141,7 +141,7 @@ describe('toBranchMatchConfig', () => {
const config = {'base-branch': ['testing'], 'head-branch': ['testing']}; const config = {'base-branch': ['testing'], 'head-branch': ['testing']};
it('sets headBranch and baseBranch in the matchConfig', () => { it('sets headBranch and baseBranch in the matchConfig', () => {
const result = toBranchMatchConfig(config); const result = toBranchMatchConfig(config);
expect(result).toMatchObject<BranchMatchConfig>({ expect(result).toEqual<BranchMatchConfig>({
baseBranch: ['testing'], baseBranch: ['testing'],
headBranch: ['testing'] headBranch: ['testing']
}); });

View File

@@ -58,32 +58,32 @@ describe('toChangedFilesMatchConfig', () => {
it('returns an empty object', () => { it('returns an empty object', () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({}); expect(result).toEqual<ChangedFilesMatchConfig>({});
});
});
describe(`when both 'any' and 'all' keys are present`, () => {
const config = {'changed-files': [{all: 'testing'}, {any: 'testing'}]};
it('sets both values in the config object', () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({
changedFiles: {
any: ['testing'],
all: ['testing']
}
});
}); });
}); });
describe(`when there is a 'changed-files' key in the config`, () => { describe(`when there is a 'changed-files' key in the config`, () => {
describe(`and both 'any' and 'all' keys are present`, () => {
const config = {'changed-files': [{all: 'testing'}, {any: 'testing'}]};
it('sets both values in the config object', () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: {
any: ['testing'],
all: ['testing']
}
});
});
});
describe(`and it contains a 'all' key`, () => { describe(`and it contains a 'all' key`, () => {
describe('with a value of a string', () => { describe('with a value of a string', () => {
const config = {'changed-files': [{all: 'testing'}]}; const config = {'changed-files': [{all: 'testing'}]};
it('sets the value to be an array of strings in the config object', () => { it('sets the value to be an array of strings in the config object', () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
all: ['testing'] all: ['testing']
} }
@@ -96,7 +96,7 @@ describe('toChangedFilesMatchConfig', () => {
it('sets the value in the config object', () => { it('sets the value in the config object', () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
all: ['testing'] all: ['testing']
} }
@@ -111,7 +111,7 @@ describe('toChangedFilesMatchConfig', () => {
it('sets the value to be an array of strings on the config object', () => { it('sets the value to be an array of strings on the config object', () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
any: ['testing'] any: ['testing']
} }
@@ -124,7 +124,7 @@ describe('toChangedFilesMatchConfig', () => {
it('sets the value in the config object', () => { it('sets the value in the config object', () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
any: ['testing'] any: ['testing']
} }
@@ -138,7 +138,7 @@ describe('toChangedFilesMatchConfig', () => {
it(`sets the string as an array under an 'any' key`, () => { it(`sets the string as an array under an 'any' key`, () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
any: ['testing'] any: ['testing']
} }
@@ -151,7 +151,20 @@ describe('toChangedFilesMatchConfig', () => {
it(`sets the array under an 'any' key`, () => { it(`sets the array under an 'any' key`, () => {
const result = toChangedFilesMatchConfig(config); const result = toChangedFilesMatchConfig(config);
expect(result).toMatchObject<ChangedFilesMatchConfig>({ expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: {
any: ['testing']
}
});
});
});
describe('and there is an unknown value in the config', () => {
const config = {'changed-files': [{any: 'testing'}, {sneaky: 'test'}]};
it(`does not set the value in the match config`, () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: { changedFiles: {
any: ['testing'] any: ['testing']
} }

View File

@@ -20,7 +20,7 @@ describe('toMatchConfig', () => {
it('returns a MatchConfig object with all options', () => { it('returns a MatchConfig object with all options', () => {
const result = toMatchConfig(config); const result = toMatchConfig(config);
expect(result).toMatchObject<MatchConfig>({ expect(result).toEqual<MatchConfig>({
changedFiles: { changedFiles: {
all: ['testing-all'], all: ['testing-all'],
any: ['testing-any'] any: ['testing-any']
@@ -35,7 +35,7 @@ describe('toMatchConfig', () => {
it('does not include the unexpected items in the returned MatchConfig object', () => { it('does not include the unexpected items in the returned MatchConfig object', () => {
const result = toMatchConfig(config); const result = toMatchConfig(config);
expect(result).toMatchObject<MatchConfig>({ expect(result).toEqual<MatchConfig>({
changedFiles: { changedFiles: {
all: ['testing-all'], all: ['testing-all'],
any: ['testing-any'] any: ['testing-any']