-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path01-js-basics-test.js
More file actions
68 lines (54 loc) · 2.2 KB
/
01-js-basics-test.js
File metadata and controls
68 lines (54 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const test = require('tape');
// This is not a comprehensive view of javascript,
// just an intro to get your feet wet
//
// Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements
// Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators
//
test('javascript can do basic arithmatic', (t) => {
// This is the nubmer of test we intended to have
// in this given case
t.plan(4);
// Make the following tests pass by changing "WAT"
// to the value that should result in the operation
// on the left
t.equal(4 + 5, 9, "Example of javascript adding.");
t.equal(31 - 5, "WAT", "It can subtract!");
t.equal(6 * 8, "WAT", "It can multiply!");
t.equal((2 + 2) * 2 + 2 * 2, "WAT", "It can chain operations!");
});
test('javascript can do logic', (t) => {
// This is the nubmer of test we intended to have
// in this given case
t.plan(7);
// Make the following tests pass by changing "WAT"
// to the value that should result in the operation
// on the left
t.equal(1 > 5, false, "It can do Greater than!");
t.equal(1 < 5, true, "It can do Less than!");
t.equal(99 >= 99, "WAT", "It can do Greater than or equal to!");
t.equal(7 === 5, "WAT", "It can do equality!");
t.equal(7 !== 5, "WAT", "It can do inequality!");
t.equal(true && true, "WAT", "It can do logical and");
t.equal(true || false, "WAT", "It can do logical or!");
});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
test('javascript has arrays', (t) => {
t.equal([1, 2, 4].length, 3, "An array with three items has a lenght of three");
const a = [1, 2, 4];
t.equal(a[0], "WAT", "Arrays in javascript are indexed started with zero");
t.equal(a.pop(), "WAT", "Arrays have useful methods that can be called on");
});
test('javascript has objects', (t) => {
const book = {
title: 'everybody poops',
author: 'somebody',
yearPublished: 1995,
randoFunction: function() {
return 3 + 5;
}
};
t.equal(book.title, "WAT", "You can access properties on an object");
t.equal(book.yearPublished, "WAT", "You can store any type of data on an object");
t.equal(book.randoFunction(), "WAT", "Including a function");
});