1 | import chai from 'chai'
|
2 | import { extend, convert_from_camel_case, replace_all, starts_with, ends_with } from './../source/helpers'
|
3 |
|
4 | chai.should()
|
5 |
|
6 | describe('helpers', function()
|
7 | {
|
8 | it('should extend JSON objects', function()
|
9 | {
|
10 | const a =
|
11 | {
|
12 | a:
|
13 | {
|
14 | b: 1
|
15 | }
|
16 | }
|
17 |
|
18 | const b =
|
19 | {
|
20 | a:
|
21 | {
|
22 | c: 1
|
23 | },
|
24 | d:
|
25 | {
|
26 | e: 2
|
27 | }
|
28 | }
|
29 |
|
30 | const c =
|
31 | {
|
32 | d:
|
33 | {
|
34 | e: 3,
|
35 | f: 4
|
36 | }
|
37 | }
|
38 |
|
39 | extend(a, b, c)
|
40 |
|
41 | b.d.e.should.equal(2)
|
42 |
|
43 | const ab =
|
44 | {
|
45 | a:
|
46 | {
|
47 | b: 1,
|
48 | c: 1
|
49 | },
|
50 | d:
|
51 | {
|
52 | e: 3,
|
53 | f: 4
|
54 | }
|
55 | }
|
56 |
|
57 | a.should.deep.equal(ab)
|
58 | })
|
59 |
|
60 | it('should convert from camel case', function()
|
61 | {
|
62 | const camel_cased_a =
|
63 | {
|
64 | a: 1,
|
65 |
|
66 | bCdEf:
|
67 | {
|
68 | g_h: true
|
69 | }
|
70 | }
|
71 |
|
72 | const a =
|
73 | {
|
74 | a: 1,
|
75 |
|
76 | b_cd_ef:
|
77 | {
|
78 | g_h: true
|
79 | }
|
80 | }
|
81 |
|
82 | convert_from_camel_case(camel_cased_a).should.deep.equal(a)
|
83 | })
|
84 |
|
85 | it('should replace strings', function()
|
86 | {
|
87 | replace_all('Testing \\ string', '\\', '-').should.equal('Testing - string')
|
88 | })
|
89 |
|
90 | it('should determine if a string starts with a substring', function()
|
91 | {
|
92 | starts_with('#$% test', '#').should.equal(true)
|
93 | starts_with('#$% test', '$').should.equal(false)
|
94 | })
|
95 |
|
96 | it('should determine if a string ends with a substring', function()
|
97 | {
|
98 | ends_with('#$% test !', '!').should.equal(true)
|
99 | ends_with('#$% test !', '#').should.equal(false)
|
100 | })
|
101 | }) |
\ | No newline at end of file |