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 | }
|
36 | }
|
37 |
|
38 | extend(a, b, c)
|
39 |
|
40 | b.d.e.should.equal(2)
|
41 |
|
42 | const ab =
|
43 | {
|
44 | a:
|
45 | {
|
46 | b: 1,
|
47 | c: 1
|
48 | },
|
49 | d:
|
50 | {
|
51 | e: 3
|
52 | }
|
53 | }
|
54 |
|
55 | a.should.deep.equal(ab)
|
56 | })
|
57 |
|
58 | it('should convert from camel case', function()
|
59 | {
|
60 | const camel_cased_a =
|
61 | {
|
62 | a: 1,
|
63 |
|
64 | bCdEf:
|
65 | {
|
66 | g_h: true
|
67 | }
|
68 | }
|
69 |
|
70 | const a =
|
71 | {
|
72 | a: 1,
|
73 |
|
74 | b_cd_ef:
|
75 | {
|
76 | g_h: true
|
77 | }
|
78 | }
|
79 |
|
80 | convert_from_camel_case(camel_cased_a).should.deep.equal(a)
|
81 | })
|
82 |
|
83 | it('should replace strings', function()
|
84 | {
|
85 | replace_all('Testing \\ string', '\\', '-').should.equal('Testing - string')
|
86 | })
|
87 |
|
88 | it('should determine if a string starts with a substring', function()
|
89 | {
|
90 | starts_with('#$% test', '#').should.equal(true)
|
91 | starts_with('#$% test', '$').should.equal(false)
|
92 | })
|
93 |
|
94 | it('should determine if a string ends with a substring', function()
|
95 | {
|
96 | ends_with('#$% test !', '!').should.equal(true)
|
97 | ends_with('#$% test !', '#').should.equal(false)
|
98 | })
|
99 | }) |
\ | No newline at end of file |