Issues (204)

test/InterfaceBuilder/InstanceOfTest.js (1 issue)

Severity
1
/* Javascript Object Inheritance Implementation                ______  ________
2
 * (c) 2016 <[email protected]>                             __ / / __ \/  _/  _/
3
 * Licensed under MIT.                                    / // / /_/ // /_/ /
4
 * ------------------------------------------------------ \___/\____/___/__*/
5
var JOII = require('../../dist/joii').JOII;
6
7
/**
8
* Tests instanceOf functionality.
9
*/
10
test('InterfaceBuilder:InstanceOfTest', function(assert) {
11
12
    var I1 = JOII.InterfaceBuilder({});
0 ignored issues
show
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
13
    var I2 = JOII.InterfaceBuilder({});
14
    var I3 = JOII.InterfaceBuilder({});
15
    var I4 = JOII.InterfaceBuilder({});
16
17
    var c1Base = JOII.ClassBuilder({'implements': I1}, {});
18
    var c1 = new c1Base();
19
    assert.strictEqual(c1.instanceOf(c1Base), true, 'c1 is an instance of c1Base');
20
    assert.strictEqual(c1.instanceOf(I1), true, 'c1 is an instance of I1');
21
    assert.strictEqual(c1.instanceOf(I2), false, 'c1 is NOT an instance of I2');
22
23
    var c1Child = JOII.ClassBuilder({'extends': c1Base}, {});
24
    var c1a = new c1Child();
25
    assert.strictEqual(c1a.instanceOf(c1Base), true, 'c1a is an instance of c1Base');
26
    assert.strictEqual(c1a.instanceOf(c1Child), true, 'c1a is an instance of c1Child');
27
    assert.strictEqual(c1a.instanceOf(I1), true, 'c1a is an instance of I1');
28
    assert.strictEqual(c1a.instanceOf(I2), false, 'c1a is NOT an instance of I2');
29
30
    var c2Child = JOII.ClassBuilder({'extends': c1Child, 'implements' : [I2, I3]}, {});
31
    var c1b = new c2Child();
32
    assert.strictEqual(c1b.instanceOf(c1Base), true, 'c1b is an instance of c1Base');
33
    assert.strictEqual(c1b.instanceOf(c1Child), true, 'c1b is an instance of c1Child');
34
    assert.strictEqual(c1b.instanceOf(I1), true, 'c1b is an instance of I1');
35
    assert.strictEqual(c1b.instanceOf(I2), true, 'c1b is an instance of I2');
36
37
    var c3Child = JOII.ClassBuilder({'extends': c1Base, 'implements' : [I2, I4]}, {});
38
    var c1c = new c3Child();
39
    assert.strictEqual(c1c.instanceOf(c1Base), true, 'c1b is an instance of c1Base');
40
    assert.strictEqual(c1c.instanceOf(c1Child), false, 'c1b is NOT an instance of c1Child');
41
    assert.strictEqual(c1c.instanceOf(c2Child), false, 'c1b is NOT an instance of c2Child');
42
    assert.strictEqual(c1c.instanceOf(I1), true, 'c1b is an instance of I1');
43
    assert.strictEqual(c1c.instanceOf(I2), true, 'c1b is an instance of I2');
44
45
    assert.strictEqual(c1.instanceOf(I2), false, 'c1 is still NOT an instance of I2');
46
});
47