Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
da6eb0cf
Commit
da6eb0cf
authored
May 21, 2020
by
Nicolò Maria Mezzopera
Committed by
Illya Klymov
May 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new matcher for interpolated strings
- matcher - matchers test
parent
b87b02f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
spec/frontend/matchers.js
spec/frontend/matchers.js
+33
-0
spec/frontend/matchers_spec.js
spec/frontend/matchers_spec.js
+48
-0
No files found.
spec/frontend/matchers.js
View file @
da6eb0cf
...
@@ -35,4 +35,37 @@ export default {
...
@@ -35,4 +35,37 @@ export default {
message
:
()
=>
message
,
message
:
()
=>
message
,
};
};
},
},
toMatchInterpolatedText
(
received
,
match
)
{
let
clearReceived
;
let
clearMatch
;
try
{
clearReceived
=
received
.
replace
(
/
\s\s
+/gm
,
'
'
)
.
replace
(
/
\s\.
/gm
,
'
.
'
)
.
trim
();
}
catch
(
e
)
{
return
{
actual
:
received
,
message
:
'
The received value is not a string
'
,
pass
:
false
};
}
try
{
clearMatch
=
match
.
replace
(
/%{
\w
+}/gm
,
''
).
trim
();
}
catch
(
e
)
{
return
{
message
:
'
The comparator value is not a string
'
,
pass
:
false
};
}
const
pass
=
clearReceived
===
clearMatch
;
const
message
=
pass
?
()
=>
`
\n\n
Expected:
${
this
.
utils
.
printExpected
(
clearReceived
)}
To not equal:
${
this
.
utils
.
printReceived
(
clearMatch
)}
`
:
()
=>
`
\n\n
Expected:
${
this
.
utils
.
printExpected
(
clearReceived
)}
To equal:
${
this
.
utils
.
printReceived
(
clearMatch
)}
`
;
return
{
actual
:
received
,
message
,
pass
};
},
};
};
spec/frontend/matchers_spec.js
0 → 100644
View file @
da6eb0cf
describe
(
'
Custom jest matchers
'
,
()
=>
{
describe
(
'
toMatchInterpolatedText
'
,
()
=>
{
describe
(
'
malformed input
'
,
()
=>
{
it
.
each
([
null
,
1
,
Symbol
,
Array
,
Object
])(
'
fails graciously if the expected value is %s
'
,
expected
=>
{
expect
(
expected
).
not
.
toMatchInterpolatedText
(
'
null
'
);
},
);
});
describe
(
'
malformed matcher
'
,
()
=>
{
it
.
each
([
null
,
1
,
Symbol
,
Array
,
Object
])(
'
fails graciously if the matcher is %s
'
,
matcher
=>
{
expect
(
'
null
'
).
not
.
toMatchInterpolatedText
(
matcher
);
},
);
});
describe
(
'
positive assertion
'
,
()
=>
{
it
.
each
`
htmlString | templateString
${
'
foo
'
}
|
${
'
foo
'
}
${
'
foo
'
}
|
${
'
foo%{foo}
'
}
${
'
foo
'
}
|
${
'
foo
'
}
${
'
foo
'
}
|
${
'
foo%{foo}
'
}
${
'
foo .
'
}
|
${
'
foo%{foo}.
'
}
${
'
foo bar .
'
}
|
${
'
foo%{foo} bar.
'
}
${
'
foo
\n\n
bar .
'
}
|
${
'
foo%{foo} bar.
'
}
${
'
foo bar . .
'
}
|
${
'
foo%{fooStart} bar.%{fooEnd}.
'
}
`
(
'
$htmlString equals $templateString
'
,
({
htmlString
,
templateString
})
=>
{
expect
(
htmlString
).
toMatchInterpolatedText
(
templateString
);
});
});
describe
(
'
negative assertion
'
,
()
=>
{
it
.
each
`
htmlString | templateString
${
'
foo
'
}
|
${
'
bar
'
}
${
'
foo
'
}
|
${
'
bar%{foo}
'
}
${
'
foo
'
}
|
${
'
@{lol}foo%{foo}
'
}
${
'
fo o
'
}
|
${
'
foo
'
}
`
(
'
$htmlString does not equal $templateString
'
,
({
htmlString
,
templateString
})
=>
{
expect
(
htmlString
).
not
.
toMatchInterpolatedText
(
templateString
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment