-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathparams_spec.js
114 lines (99 loc) · 3.31 KB
/
params_spec.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* global it, describe */
/**
* Module Dependencies
*/
var params = require('../lib/params')
var assert = require('assert')
/**
* Tests
*/
describe('params', function () {
describe('1 arguments', function () {
it("should be a selector if it's a string", function () {
var arg = params('#hi')
assert.equal(null, arg.source)
assert.equal(null, arg.context)
assert.equal('#hi', arg.selector)
})
it("should be a selector if it's an object", function () {
var arg = params({ hi: 'hi' })
assert.equal(null, arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, {
hi: 'hi'
})
})
it("should be a selector if it's an array", function () {
var arg = params(['hi'])
assert.equal(null, arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, ['hi'])
})
})
describe('2 arguments', function () {
it('should support attribute selectors', function () {
var arg = params('@attr', { hi: 'hi' })
assert.equal(null, arg.source)
assert.equal('@attr', arg.context)
assert.deepEqual(arg.selector, {
hi: 'hi'
})
})
it('should support selectors', function () {
var arg = params('.hi', { hi: 'hi' })
assert.equal(null, arg.source)
assert.equal('.hi', arg.context)
assert.deepEqual(arg.selector, {
hi: 'hi'
})
})
it('should support urls with object selectors', function () {
var arg = params('https://google.com', { hi: 'hi' })
assert.equal('https://google.com', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, {
hi: 'hi'
})
})
it('should support urls with string selectors', function () {
var arg = params('https://google.com', 'hi')
assert.equal('https://google.com', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, 'hi')
})
it('should support urls with array selectors', function () {
var arg = params('https://google.com', ['hi'])
assert.equal('https://google.com', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, ['hi'])
})
it('should support HTML strings with object selectors', function () {
var arg = params('<h2>hi</h2>', { hi: 'hi' })
assert.equal('<h2>hi</h2>', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, {
hi: 'hi'
})
})
it('should support HTML strings with string selectors', function () {
var arg = params('<h2>hi</h2>', 'hi')
assert.equal('<h2>hi</h2>', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, 'hi')
})
it('should support HTML strings with array selectors', function () {
var arg = params('<h2>hi</h2>', ['hi'])
assert.equal('<h2>hi</h2>', arg.source)
assert.equal(null, arg.context)
assert.deepEqual(arg.selector, ['hi'])
})
})
describe('3 arguments', function () {
it('should support a source, context, and selector', function () {
var arg = params('http://google.com', '#hi', { hi: 'hi' })
assert.equal('http://google.com', arg.source)
assert.equal('#hi', arg.context)
assert.deepEqual({ hi: 'hi' }, arg.selector)
})
})
})