Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 21:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 21:09:24 +0300
commit2857ba3ce5c9272b99ab2cc4a3d2564504d7ed0e (patch)
tree68ff07158ac0d73d898fa08a4cbaef52fb535e7a /spec/frontend/__helpers__
parentf805496e2f458cc234ac5e52d09fa6d787ccaa97 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/__helpers__')
-rw-r--r--spec/frontend/__helpers__/matchers/index.js1
-rw-r--r--spec/frontend/__helpers__/matchers/to_equal_graphql_fixture.js28
-rw-r--r--spec/frontend/__helpers__/matchers/to_equal_graphql_fixture_spec.js58
3 files changed, 87 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/matchers/index.js b/spec/frontend/__helpers__/matchers/index.js
index 5da6676cdc1..73464135950 100644
--- a/spec/frontend/__helpers__/matchers/index.js
+++ b/spec/frontend/__helpers__/matchers/index.js
@@ -3,3 +3,4 @@ export * from './to_have_tracking_attributes';
export * from './to_match_interpolated_text';
export * from './to_validate_json_schema';
export * from './to_match_expected_for_markdown';
+export * from './to_equal_graphql_fixture';
diff --git a/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture.js b/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture.js
new file mode 100644
index 00000000000..1a095de1deb
--- /dev/null
+++ b/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture.js
@@ -0,0 +1,28 @@
+import { isEqual } from 'lodash';
+import { stripTypenames } from 'helpers/graphql_helpers';
+
+export function toEqualGraphqlFixture(received, match) {
+ let clearReceived;
+ let clearMatch;
+
+ try {
+ clearReceived = JSON.parse(JSON.stringify(received));
+ clearMatch = stripTypenames(match);
+ } catch (e) {
+ return { message: () => 'The comparator value is not an object', pass: false };
+ }
+ const pass = isEqual(clearReceived, clearMatch);
+ // console.log(this.utils);
+ const message = pass
+ ? () => `
+ Expected to not be: ${this.utils.printExpected(clearMatch)}
+ Received: ${this.utils.printReceived(clearReceived)}
+ `
+ : () =>
+ `
+ Expected to be: ${this.utils.printExpected(clearMatch)}
+ Received: ${this.utils.printReceived(clearReceived)}
+ `;
+
+ return { actual: received, message, pass };
+}
diff --git a/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture_spec.js b/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture_spec.js
new file mode 100644
index 00000000000..00adc8cfc8d
--- /dev/null
+++ b/spec/frontend/__helpers__/matchers/to_equal_graphql_fixture_spec.js
@@ -0,0 +1,58 @@
+describe('custom matcher toEqualGraphqlFixture', () => {
+ const key = 'value';
+ const key2 = 'value2';
+
+ describe('positive assertion', () => {
+ it.each([
+ [{}, {}],
+ [{ undef: undefined }, { undef: undefined }],
+ [{}, { __typename: 'MyType' }],
+ [{ key }, { key, __typename: 'MyType' }],
+ [
+ { obj: { key } },
+ {
+ obj: {
+ key,
+ __typename: 'MyNestedType',
+ },
+ __typename: 'MyType',
+ },
+ ],
+ [[{ key }], [{ key }]],
+ [
+ [{ key }],
+ [
+ {
+ key,
+ __typename: 'MyCollectionType',
+ },
+ ],
+ ],
+ ])('%j equals %j', (received, match) => {
+ expect(received).toEqualGraphqlFixture(match);
+ });
+ });
+
+ describe('negative assertion', () => {
+ it.each([
+ [{ __typename: 'MyType' }, {}],
+ [{ key }, { key2, __typename: 'MyType' }],
+ [
+ { key, key2 },
+ { key2, __typename: 'MyType' },
+ ],
+ [[{ key }, { key2 }], [{ key }]],
+ [
+ [{ key, key2 }],
+ [
+ {
+ key,
+ __typename: 'MyCollectionType',
+ },
+ ],
+ ],
+ ])('%j does not equal %j', (received, match) => {
+ expect(received).not.toEqualGraphqlFixture(match);
+ });
+ });
+});