Skip to content

Commit c5dcef2

Browse files
authored
Merge pull request #14 from getmimo/loriana/ch24665/adapt-the-test-that-loosely-checks-element
Update Test To Check For First And Last Word
2 parents 1cd8316 + b3f121a commit c5dcef2

File tree

8 files changed

+51
-32
lines changed

8 files changed

+51
-32
lines changed

dist/index.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@getmimo/sphinx",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "A library of testing functions which can be used in jest to validate various html, javascript or css files",
55
"repository": "git://github.com/getmimo/sphinx.git",
66
"main": "dist/index.js",
@@ -32,6 +32,7 @@
3232
"jsdom-global": "^3.0.2",
3333
"lint-staged": "^10.0.9",
3434
"node-html-parser": "^1.1.16",
35+
"prettier": "^2.0.4",
3536
"rewire": "^4.0.1",
3637
"typescript": "^3.5.3"
3738
},

src/examples/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>abc a\n d</title>
4+
<title>abc \sdgjh d</title>
55
</head>
66
<body>
77
<h1>Bear of the Year</h1>
8+
<h2>abc d</h2>
9+
<h3>abc abc \n \n abcd ade d d</h3>
10+
<span>abc</span>
811
<img src="https://mimo.app/r/panda.png" />
912
<p><em>Nom nom nom</em></p>
1013
<p>3 votes</p>

src/examples/index.test.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let sphinx = require('../../dist/index.js').buildSphinx(
88
test,
99
expect,
1010
);
11+
let { isTextSimilar } = require('../../dist/index.js');
1112

1213
sphinx.test('Make sure to start your code with: <!doctype html>.', () => {
1314
openingTagIndex = htmlCode.indexOf('<!DOCTYPE html>');
@@ -56,13 +57,25 @@ sphinx.firstElementIsInsideSecond({
5657
secondElementName: 'p',
5758
});
5859

59-
// sphinx.elementTextIsSet({ elementName: 'h1' });
60-
// sphinx.elementTextIsSet({ elementName: 'p' });
61-
// sphinx.elementTextIsSet({ elementName: 'em' });
62-
// sphinx.elementTextIsSet({ elementName: 'p', text: '3 votes' });
63-
// sphinx.elementTextIsSet({ elementName: 'title', text: 'ab' });
60+
//test should pass if the user's text is equal to the sample text (for texts of length > 1)
61+
sphinx.elementTextIsSetLoose({ elementName: 'title', text: 'abc a\n d' });
62+
//test should pass if the user's text contains only the first and last words of the sample text
63+
sphinx.elementTextIsSetLoose({ elementName: 'h2', text: 'abc a\n d' });
64+
//test should pass if the user's text contains only the first word of the sample text, if the sample text's length is 1
65+
sphinx.elementTextIsSetLoose({ elementName: 'span', text: 'abc' });
6466

65-
sphinx.elementTextIsSetLoose({ elementName: 'title', text: 'abc a d' });
67+
test('Test should fail when the user\'s text doesn\'t contain the last word of the sample text', () => {
68+
expect(isTextSimilar(root, 'title', 'abc a\n m')).toBe(false);
69+
});
70+
test('Test should fail when the user\'s text doesn\'t contain the first word of the sample text', () => {
71+
expect(isTextSimilar(root, 'title', 'ab a\n d')).toBe(false);
72+
});
73+
test('Test should fail when the user\'s text doesn\'t contain the first and last words of the sample text', () => {
74+
expect(isTextSimilar(root, 'title', 'ab a\n m')).toBe(false);
75+
});
76+
test('Test should fail when the sample text\'s length is greater than one, but the user\'s text length is less than or equal to one', () => {
77+
expect(isTextSimilar(root, 'span', 'abc d')).toBe(false);
78+
});
6679

6780
sphinx.elementAttributeSetToCorrectValue({
6881
elementName: 'script',

src/examples/jsdom.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sphinx.elementCSSPropertySet({
3434
propertyValue: '0px',
3535
});
3636

37-
sphinx.elementCSSPropertySetWithCustomPropertyValue ({
37+
sphinx.elementCSSPropertySetWithCustomPropertyValue({
3838
elementSelector: 'h1',
3939
propertyName: 'font-size',
4040
propertyValue: '33px',

0 commit comments

Comments
 (0)