Updated English guide articles for all QA and Testing with Chai challenges (#35080)

* Updated guide articles for all Quality Assurance and Testing with Chai challenges to include hints and solutions

* fix: 2 space indentation and code formatting
pull/36364/head
orangegrove1955 2019-07-02 07:00:18 +10:00 committed by Tom
parent e05e17ce31
commit 27ae86f0ef
24 changed files with 603 additions and 72 deletions

View File

@ -3,8 +3,24 @@ title: Assert Deep Equality with .deepEqual and .notDeepEqual
---
## Assert Deep Equality with .deepEqual and .notDeepEqual
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/assert-deep-equality-with-.deepequal-and-.notdeepequal/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Equality'
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ` /** 7 */` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
Deep equality checks if two objects, and their child objects, are equal to one another using the `==` operator.
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.deepEqual()` or `assert.notDeepEqual()`
## Solution
```js
/** 7 - .deepEqual(), .notDeepEqual() **/
// .deepEqual() asserts that two object are deep equal
test('#deepEqual, #notDeepEqual', function() {
assert.deepEqual( { a: '1', b: 5 } , { b: 5, a: '1' }, "keys order doesn't matter" );
assert.notDeepEqual( { a: [5, 6] }, { a: [6, 5] }, "array elements position does matter !!" );
});
```

View File

@ -3,8 +3,26 @@ title: Compare the Properties of Two Elements
---
## Compare the Properties of Two Elements
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/compare-the-properties-of-two-elements/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Comparisons'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ` /** 8 */` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
`isAbove()` compares if the first parameter is greater than the second `(a > b)`
`isAtMost()` compares if the first parameter is equal to or less than the second `(a <= b)`
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.isAbove()` or `assert.isAtMost()`.
## Solution
```js
/** 8 - .isAbove() => a > b , .isAtMost() => a <= b **/
test('#isAbove, #isAtMost', function() {
assert.isAtMost('hello'.length , 5);
assert.isAbove(1, 0);
assert.isAbove(Math.PI, 3);
assert.isAtMost(1 - Math.random(), 1);
});
```

View File

@ -3,8 +3,20 @@ title: Learn How JavaScript Assertions Work
---
## Learn How JavaScript Assertions Work
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/learn-how-javascript-assertions-work/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js".
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this first challenge requires you to make the tests in ` /** 1 */` to pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The two lines in the test should be changed from `assert.fail()` to either `assert.isNull()` or `assert.isNotNull()`.
## Solution
```js
/** 1 - Use assert.isNull() or assert.isNotNull() to make the tests pass. **/
test('#isNull, #isNotNull', function() {
assert.isNull(null, 'this is an optional error description - e.g. null is null');
assert.isNotNull( 1, '1 is not null');
});
```

View File

@ -3,8 +3,40 @@ title: Run Functional Tests on an API Response using Chai-HTTP III - PUT method
---
## Run Functional Tests on an API Response using Chai-HTTP III - PUT method
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-on-an-api-response-using-chai-http-iii---put-method/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate the test 'send {surname: "Colombo"}'
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
## Hint 1
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Using the example above, look at the assertions and how they are making comparisons between the expected and actual values of the response
## Hint 2
You need to use .send() to attach the payload `{surname: 'Colombo'}` to the request
## Hint 3
Replace the `assert.fail()` statement with your own tests checking for status, type, body.name, and body.surname in that order. Remember, all of these values are contained in the response (`res`), and you should expect the response to be of type `'application/json'`.
## Solution
```js
test('send {surname: "Colombo"}', function(done){
// we setup the request for you...
chai.request(server)
.put('/travellers')
/** send {surname: 'Colombo'} here **/
.send({surname: 'Colombo'})
// .send({...})
.end(function(err, res){
/** your tests here **/
assert.equal(res.status, 200, 'response status should be 200');
assert.equal(res.type, 'application/json', "Response should be json");
assert.equal(res.body.name, 'Cristoforo', 'res.body.name should be "Christoforo"');
assert.equal(res.body.surname, 'Colombo', 'res.body.surname should be "Colombo"');
done(); // Never forget the 'done()' callback...
});
});
```

View File

@ -3,8 +3,49 @@ title: Run Functional Tests on an API Response using Chai-HTTP IV - PUT method
---
## Run Functional Tests on an API Response using Chai-HTTP IV - PUT method
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-on-an-api-response-using-chai-http-iv---put-method/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate the test 'send {surname: "da Verrazzano"}'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
## Hint 1
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Using the example above, look how the request is being sent, and how the assertions are making comparisons between the expected and actual values of the response.
## Hint 2
Make sure you are placing a request through `chai.request(server)`.
## Hint 3
You need to use make a .put() request to `/travellers` and use .send() to attach the payload `{surname: 'da Verrazzano'}` to the request.
## Hint 4
Replace the assert.fail() statement with your own tests checking for status, type, body.name, and body.surname in that order. Remember, all of these values are contained in the response `(res`), and you should expect the response to be of type `'application/json'`.
## Hint 5
Check the tests on the challenge page to determine the expected values for `body.name` and `body.surname`.
## Hint 6
Ensure your call to `done()` is inside your callback function for the tests.
## Solution
```js
test('send {surname: "da Verrazzano"}', function(done) {
/** place the chai-http request code here... **/
chai.request(server)
.put('/travellers')
.send({surname: 'da Verrazzano'})
/** place your tests inside the callback **/
.end(function(err, res){
assert.equal(res.status, 200, 'response status should be 200');
assert.equal(res.type, 'application/json', "Response should be json");
assert.equal(res.body.name, 'Giovanni');
assert.equal(res.body.surname, 'da Verrazzano');
done();
});
});
```

View File

@ -3,8 +3,34 @@ title: Run Functional Tests on API Endpoints using Chai-HTTP II
---
## Run Functional Tests on API Endpoints using Chai-HTTP II
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-on-api-endpoints-using-chai-http-ii/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate 'Test GET /hello with your name'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
## Hint 1
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Using the example above, look at the assertions and how they are making comparisons between the expected and actual values of the response.
## Hint 2
Make sure you have entered your own name (or whichever name you are inputting) into both the query (line 67)and the assertion for `res.text` (line 74) in order for the test to pass.
## Hint 3
The lines in the test should be changed from `assert.fail()` to an assertion that checks if the two values are equal.
## Solution
```js
test('Test GET /hello with your name', function(done){ // Don't forget the callback...
chai.request(server) // 'server' is the Express App
.get('/hello?name=John') /** <=== Put your name in the query **/
.end(function(err, res){ // res is the response object
// Your tests here.
// Replace assert.fail(). Make the test pass.
// Test the status and the text response. Follow the test order like above.
assert.equal(res.status, 200);
assert.equal(res.text, 'hello John'/** <== Put your name here **/);
done(); // Always call the 'done()' callback when finished.
});
});
```

View File

@ -3,8 +3,30 @@ title: Run Functional Tests on API Endpoints using Chai-HTTP
---
## Run Functional Tests on API Endpoints using Chai-HTTP
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-on-api-endpoints-using-chai-http/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate 'Test GET /hello with no name'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
## Hint 1
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Using the example above, look at the assertions and how they are making comparisons between the expected and actual values of the response.
## Hint 2
The lines in the test should be changed from `assert.fail()` to an assertion that checks if the two values are equal.
## Solution
```js
test('Test GET /hello with no name', function(done){ // Don't forget the callback...
chai.request(server) // 'server' is the Express App
.get('/hello') // http_method(url). NO NAME in the query !
.end(function(err, res){ // res is the response object
// Test the status and the text response (see the example above).
// Please follow the order -status, -text. We rely on that in our tests.
// It should respond 'Hello Guest'
assert.equal(res.status, 200);
assert.equal(res.text, 'hello Guest');
done(); // Always call the 'done()' callback when finished.
});
});
```

View File

@ -3,8 +3,55 @@ title: Run Functional Tests using a Headless Browser II
---
## Run Functional Tests using a Headless Browser II
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-using-a-headless-browser-ii/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate the browser based tests.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
Change the Browser.site link to the current URL of your project if you are completing this challenge online. If you are using a local development environment, replace the line with ```Browser.localhost('example.com', (process.env.PORT || 3000));```.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Find test 'submit "surname" : "Vespucci" - write your e2e test...' and check the challenge page for the expected values in order to pass this challenge.
## Hint 1
Using the example above, look at how the form is being submitted, and how the assertions are making comparisons between the expected and actual values of the response.
## Hint 2
Fill the broswer with a surname of Vespucci, then use pressButton to submit.
## Hint 3
In the callback for pressButton, all assertions should be browser.assert in order to correctly pass.
## Hint 4
Replace the `assert.fail()` statement with your own tests based on the instructions in the comments. Check the example above for syntax if you get stuck.
## Hint 4
Check the tests on the challenge page or the instructions in the comments for expected values.
## Hint 5
Make sure your `done()` call is within the pressButton callback.
## Solution
```js
test('submit "surname" : "Vespucci" - write your e2e test...', function(done) {
// fill the form, and submit.
browser
.fill('surname', 'Vespucci')
.pressButton('submit', function(){
// assert that status is OK 200
browser.assert.success();
// assert that the text inside the element 'span#name' is 'Amerigo'
browser.assert.text('span#name', 'Amerigo');
// assert that the text inside the element 'span#surname' is 'Vespucci'
browser.assert.text('span#surname', 'Vespucci');
// assert that the element(s) 'span#dates' exist and their count is 1
browser.assert.element('span#dates', 1);
done();
});
});
```

View File

@ -3,8 +3,59 @@ title: Run Functional Tests using a Headless Browser
---
## Run Functional Tests using a Headless Browser
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-using-a-headless-browser/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, open the file "tests/2_functional_tests.js" and locate the browser based tests.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
Change the Browser.site link to the current URL of your project if you are completing this challenge online. If you are using a local development environment, replace the line with ```Browser.localhost('example.com', (process.env.PORT || 3000));```.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Find test 'submit "surname" : "Colombo" - write your e2e test...' and read the instructions to determine how to pass this challenge.
## Hint 1
Using the example above, look at how the assertions are making comparisons between the expected and actual values of the response.
## Hint 2
All assertions should be browser.assert in order to correctly pass.
## Hint 3
Replace the `assert.fail()` statement with your own tests based on the instructions in the comments. Check the example above for syntax if you get stuck.
## Hint 4
Check the tests on the challenge page for expected values.
## Solution
```js
test('submit "surname" : "Colombo" - write your e2e test...', function(done) {
// fill the form...
// then submit it pressing 'submit' button.
//
// in the callback...
// assert that status is OK 200
// assert that the text inside the element 'span#name' is 'Cristoforo'
// assert that the text inside the element 'span#surname' is 'Colombo'
// assert that the element(s) 'span#dates' exist and their count is 1
browser
.fill('surname', 'Colombo')
.pressButton('submit', function(){
/** YOUR TESTS HERE, Don't forget to remove assert.fail() **/
// pressButton is Async. Waits for the ajax call to complete...
// assert that status is OK 200
browser.assert.success();
// assert that the text inside the element 'span#name' is 'Cristoforo'
browser.assert.text('span#name', 'Cristoforo');
// assert that the text inside the element 'span#surname' is 'Colombo'
browser.assert.text('span#surname', 'Colombo');
// assert that the element(s) 'span#dates' exist and their count is 1
browser.assert.element('span#dates', 1);
done(); // It's an async test, so we have to call 'done()''
});
});
```

View File

@ -3,8 +3,22 @@ title: Test for Truthiness
---
## Test for Truthiness
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-for-truthiness/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js".
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 4 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.isTrue()` or `assert.isNotTrue()`.
## Solution
```js
/** 4 - Use assert.isTrue() or assert.isNotTrue() to make the tests pass. **/
// .isTrue(true) and .isNotTrue(everything else) will pass.
// .isFalse() and .isNotFalse() also exist.
test('#isTrue, #isNotTrue', function(){
assert.isTrue( true, 'true is true');
assert.isTrue( !!'double negation', 'double negation of a truthy is true');
assert.isNotTrue({ value: 'truthy' }, 'A truthy object is NOT TRUE (neither is false...)' );
});
```

View File

@ -3,8 +3,28 @@ title: Test if a String Contains a Substring
---
## Test if a String Contains a Substring
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-string-contains-a-substring/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Strings'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 14 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
Check the responses of the error messages if your tests fail, and make sure you understand the values of the parameters being checked by the assertion.
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.include()` or `assert.notInclude()`.
## Hint 3
`assert.include()` and `assert.notInclude()` parameters take the form (haystack, needle, message) where the needle is what you are searching for in the haystack. The message provides feedback where there is an error.
## Solution
```js
/** 14 - #include (on #notInclude ) works for strings too !! **/
// It asserts that the actual string contains the expected substring
test('String #include, #notInclude', function() {
assert.include('Arrow', 'row', "Arrow contains row...");
assert.notInclude('dart', 'queue', "But a dart doesn't contain a queue");
});

View File

@ -3,8 +3,27 @@ title: Test if a Value Falls within a Specific Range
---
## Test if a Value Falls within a Specific Range
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-value-falls-within-a-specific-range/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Comparisons'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 10 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
`approximately()` requires a range to make the tests pass. The expected value for both tests is currently 1, so you need to find a range that allows for all values to be accounted for.
## Hint 2
Check the error outputs, and try to understand what the +/- values in the errors mean with respect to a possible range of values.
## Solution
```js
/** 10 - .approximately **/
// .approximately(actual, expected, range, [message])
// actual = expected +/- range
// Choose the minimum range (3rd parameter) to make the test always pass
// it should be less than 1
test('#approximately', function() {
assert.approximately(weirdNumbers(0.5) , 1, /*edit this*/ 0.5 );
assert.approximately(weirdNumbers(0.2) , 1, /*edit this*/ 0.8 );
});
```

View File

@ -3,8 +3,25 @@ title: Test if a Value is a String
---
## Test if a Value is a String
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-value-is-a-string/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Strings'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 13 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
Check the responses of the error messages if your tests fail, and make sure you understand the types of the parameters being checked by the assertion.
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.isString()` or `assert.isNotString()`.
## Solution
```js
/** 13 - #isString asserts that the actual value is a string. **/
test('#isString, #isNotString', function() {
assert.isNotString(Math.sin(Math.PI/4), 'a float is not a string');
assert.isString(process.env.PATH, 'env vars are strings (or undefined)');
assert.isString(JSON.stringify({type: 'object'}), 'a JSON is a string');
});
```

View File

@ -3,8 +3,20 @@ title: Test if a Value is an Array
---
## Test if a Value is an Array
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-value-is-an-array/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Arrays'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 11 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.isArray()` or `assert.isNotArray()`.
## Solution
```js
/** 11 - #isArray vs #isNotArray **/
test('#isArray, #isNotArray', function() {
assert.isArray('isThisAnArray?'.split(''), 'String.prototype.split() returns an Array');
assert.isNotArray([1,2,3].indexOf(2), 'indexOf returns a number.');
});
```

View File

@ -3,8 +3,33 @@ title: Test if a Value is of a Specific Data Structure Type
---
## Test if a Value is of a Specific Data Structure Type
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-value-is-of-a-specific-data-structure-type/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Objects'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 17 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The challenge uses objects defined above the tests. Look closely at both, and determine whether the object or its properties will have the type being compared against in the assertion.
## Hint 2
Check the error messages to determine if your understanding of the object or property's type was correct.
## Hint 3
The lines in the test should be changed from `assert.fail()` to either `assert.typeOf()` or `assert.notTypeOf()`.
## Solution
```js
test('#typeof, #notTypeOf', function() {
/** 17 #typeOf asserts that values type is the given string, **/
// as determined by Object.prototype.toString.
// Use #typeOf or #notTypeOf where appropriate
assert.typeOf(myCar, 'object');
assert.typeOf(myCar.model, 'string');
assert.notTypeOf(airlinePlane.wings, 'string');
assert.typeOf(airlinePlane.engines, 'array');
assert.typeOf(myCar.wheels, 'number');
});
```

View File

@ -3,8 +3,20 @@ title: Test if a Variable or Function is Defined
---
## Test if a Variable or Function is Defined
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-a-variable-or-function-is-defined/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js".
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 2 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.isDefined()` or `assert.isUndefined()`.
## Solution
```js
/** 2 - Use assert.isDefined() or assert.isUndefined() to make the tests pass. **/
test('#isDefined, #isUndefined', function(){
assert.isDefined( null, 'null is not undefined');
assert.isUndefined( undefined, 'undefined IS undefined');
assert.isDefined( 'hello', 'a string is not undefined' );
});
```

View File

@ -3,8 +3,28 @@ title: Test if an Array Contains an Item
---
## Test if an Array Contains an Item
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-an-array-contains-an-item/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Arrays'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 12 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The assertions are checking against variables defined before the 'Arrays' suite of tests, check carefully whether the array includes the value being asserted.
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.include()` or `assert.notInclude()`.
## Hint 3
`assert.include()` and `assert.notInclude()` parameters take the form (haystack, needle, message) where the needle is what you are searching for in the haystack. The message provides feedback where there is an error.
## Solution
```js
/** 12 - #include vs #notInclude **/
test('Array #include, #notInclude', function() {
assert.notInclude(winterMonths, 'jul', "It's summer in july...");
assert.include(backendLanguages, 'javascript', 'JS is a backend language !!');
});
```

View File

@ -3,8 +3,30 @@ title: Test if an Object has a Property
---
## Test if an Object has a Property
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-an-object-has-a-property/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Objects'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 16 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The challenge uses objects defined above the tests. Look closely at both, and determine whether the object will have a property or not.
## Hint 2
Check the error messages to determine if your understanding of the object's properties was correct.
## Hint 3
The lines in the test should be changed from `assert.fail()` to either `assert.property()` or `assert.notProperty()`.
## Solution
```js
/** 16 - #property asserts that the actual object has a given property. **/
// Use #property or #notProperty where appropriate
test('#property, #notProperty', function() {
assert.notProperty(myCar, 'wings', 'A car has not wings');
assert.property(airlinePlane, 'engines', 'planes have engines');
assert.property(myCar, 'wheels', 'Cars have wheels');
});
```

View File

@ -3,8 +3,32 @@ title: Test if an Object is an Instance of a Constructor
---
## Test if an Object is an Instance of a Constructor
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-an-object-is-an-instance-of-a-constructor/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Objects'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 18 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The challenge uses objects defined above the tests. Look closely at both, and determine whether the object is an instance of the type being compared against in the assertion.
## Hint 2
Check the error messages to determine if your understanding of the object's instance was correct.
## Hint 3
The lines in the test should be changed from `assert.fail()` to either `assert.instanceOf()` or `assert.notInstanceOf()`.
## Solution
```js
test('#instanceOf, #notInstanceOf', function() {
/** 18 #instanceOf asserts that an object is an instance of a constructor **/
// Use #instanceOf or #notInstanceOf where appropriate
assert.notInstanceOf(myCar, Plane);
assert.instanceOf(airlinePlane, Plane);
assert.instanceOf(airlinePlane, Object, 'everything is an Object');
assert.notInstanceOf(myCar.wheels, String );
});
```

View File

@ -3,8 +3,26 @@ title: Test if One Value is Below or At Least as Large as Another
---
## Test if One Value is Below or At Least as Large as Another
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/test-if-one-value-is-below-or-at-least-as-large-as-another/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Comparisons'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 9 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
`isBelow()` compares if the first parameter is less than the second ```(a < b)```.
`isAtLeast()` compares if the first parameter is equal to or less than the second ```(a >= b)```.
## Hint 2
The lines in the test should be changed from `assert.fail()` to either `assert.isBelow()` or `assert.isAtLeast()`.
## Solution
```js
/** 9 - .isBelow() => a < b , .isAtLeast => a >= b **/
test('#isBelow, #isAtLeast', function() {
assert.isAtLeast('world'.length , 5);
assert.isAtLeast(2*Math.random(), 0);
assert.isBelow(5 % 2, 2);
assert.isBelow(2/3, 1);
});
```

View File

@ -3,8 +3,21 @@ title: Use Assert.isOK and Assert.isNotOK
---
## Use Assert.isOK and Assert.isNotOK
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/use-assert.isok-and-assert.isnotok/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js".
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 3 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.isOk()` or `assert.isNotOk()`.
## Solution
```js
/** 3 - Use assert.isOk() or assert.isNotOk() to make the tests pass. **/
// .isOk(truthy) and .isNotOk(falsey) will pass
test('#isOk, #isNotOk', function(){
assert.isNotOk( null, 'null is falsey');
assert.isOk( "I'm truthy", 'a string is truthy');
assert.isOk( true, 'true is truthy' );
});
```

View File

@ -3,8 +3,30 @@ title: Use Regular Expressions to Test a String
---
## Use Regular Expressions to Test a String
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/use-regular-expressions-to-test-a-string/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Strings'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 15 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The challenge uses function `formatPeople()` to produce a string, and then compares this to a regex. Look closely at both, and determine whether the regex will match the returned string or not.
## Hint 2
Check the error messages to determine if your understanding of the regex match was correct.
## Hint 3
The lines in the test should be changed from `assert.fail()` to either `assert.match()` or `assert.notMatch()` based on the regex from the line above.
## Solution
```js
/** 15 - #match Asserts that th actual value **/
// matches the second argument regular expression.
test('#match, #notMatch', function() {
var regex = /^#\sname\:\s[\w\s]+,\sage\:\s\d+\s?$/;
assert.match(formatPeople('John Doe', 35), regex);
assert.notMatch(formatPeople('Paul Smith III', 'twenty-four'), regex);
});
```

View File

@ -3,8 +3,22 @@ title: Use the Double Equals to Assert Equality
---
## Use the Double Equals to Assert Equality
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/use-the-double-equals-to-assert-equality/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Equality'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 5 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.equal()` or `assert.notEqual()`.
## Solution
```js
/** 5 - .equal(), .notEqual() **/
// .equal() compares objects using '=='
test('#equal, #notEqual', function(){
assert.equal( 12, '12', 'numbers are coerced into strings with == ');
assert.notEqual( {value: 1}, {value:1}, '== compares object references');
assert.equal( 6 * '2', '12', 'no more hints...');
assert.notEqual( 6 + '2', '12', 'type your error message if you want' );
});
```

View File

@ -3,8 +3,22 @@ title: Use the Triple Equals to Assert Strict Equality
---
## Use the Triple Equals to Assert Strict Equality
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/information-security-and-quality-assurance/quality-assurance-and-testing-with-chai/use-the-triple-equals-to-assert-strict-equality/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Equality'.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 6 */``` pass.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Hint 1
The lines in the test should be changed from `assert.fail()` to either `assert.strictEqual()` or `assert.notStrictEqual()`.
## Solution
```js
/** 6 - .strictEqual(), .notStrictEqual() **/
// .strictEqual() compares objects using '==='
test('#strictEqual, #notStrictEqual', function(){
assert.notStrictEqual( 6, '6' );
assert.strictEqual( 6, 3*2 );
assert.strictEqual( 6 * '2', 12 );
assert.notStrictEqual( [1, 'a', {} ], [1, 'a', {}] );
});
```