├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── karma.conf.js ├── package.json ├── spec └── fixture_spec.coffee └── src ├── adapter.coffee ├── fixture.coffee └── index.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | spec 3 | karma.conf.js 4 | Gruntfile.js 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v0.2.6](https://github.com/billtrik/karma-fixture/tree/v0.2.6) (2016-02-13) 4 | 5 | **Closed issues:** 6 | 7 | - Modifying loaded fixture data permanently modifies fixture data [\#12](https://github.com/billtrik/karma-fixture/issues/12) 8 | 9 | [Full Changelog](https://github.com/billtrik/karma-fixture/compare/v0.2.5...v0.2.6) 10 | 11 | ## [v0.2.5](https://github.com/billtrik/karma-fixture/tree/v0.2.5) (2015-05-26) 12 | 13 | **Closed issues:** 14 | 15 | - Does not load json objects with escaped characters [\#7](https://github.com/billtrik/karma-fixture/issues/7) 16 | 17 | [Full Changelog](https://github.com/billtrik/karma-fixture/compare/v0.2.4...v0.2.5) 18 | 19 | ## [v0.2.4](https://github.com/billtrik/karma-fixture/tree/v0.2.4) (2015-05-18) 20 | 21 | **Closed issues:** 22 | 23 | - Don't eval() text in `' 12 | html_template4 = '' 13 | html_template5 = '' 14 | html_template6 = '' 15 | fixture_base = 'spec/fixtures' 16 | 17 | load_template_as_karma_json_fixures = (name, string, base = fixture_base)-> 18 | window.__json__ ?= {} 19 | window.__json__["#{base}/#{name}"] = JSON.parse(string) 20 | 21 | load_template_as_karma_html2js = (name, string, base = fixture_base)-> 22 | window.__html__ ?= {} 23 | window.__html__["#{base}/#{name}"] = string 24 | 25 | cleanup_karma_html2js_templates = -> window.__html__ = {} 26 | 27 | describe 'Fixture', -> 28 | before -> 29 | @Fixture = window.Fixture 30 | 31 | it 'is a function', -> 32 | expect(@Fixture).to.be.a 'function' 33 | 34 | describe 'instance', -> 35 | afterEach -> 36 | container = document.getElementById(@instance.id) 37 | container.parentElement.removeChild(container) 38 | @instance = null 39 | delete @instance 40 | 41 | it 'stores the id of the fixtures container in @id', -> 42 | @instance = new @Fixture() 43 | expect(@instance.id) 44 | .to.not.be.null 45 | 46 | it 'stores the base folder from where to load templates in @base', -> 47 | @instance = new @Fixture() 48 | expect(@instance.base) 49 | .to.not.be.null 50 | 51 | it "has a default value of '#{fixture_base}' for the base", -> 52 | @instance = new @Fixture() 53 | expect(@instance.base) 54 | .to.equal fixture_base 55 | 56 | it 'receives a param that changes the base value', -> 57 | @instance = new @Fixture('checkcheck') 58 | expect(@instance.base) 59 | .to.equal 'checkcheck' 60 | 61 | it 'receives the base folder from where to load templates as option', -> 62 | @instance = new @Fixture() 63 | 64 | it 'has an empty array to store json fixtures in @json', -> 65 | @instance = new @Fixture() 66 | expect(@instance.json) 67 | .to.be.an('array') 68 | .and.to.be.empty 69 | 70 | it 'has created the fixtures container element', -> 71 | @instance = new @Fixture() 72 | container = document.getElementById @instance.id 73 | expect(container).to.not.be.null 74 | 75 | it 'has a reference to the fixtures container element in @el', -> 76 | @instance = new @Fixture() 77 | container = document.getElementById @instance.id 78 | expect(@instance.el).to.equal(container) 79 | 80 | describe 'API', -> 81 | beforeEach -> 82 | @instance = new @Fixture() 83 | @fixture_cont = @instance.el 84 | 85 | afterEach -> 86 | container = document.getElementById(@instance.id) 87 | container.parentElement.removeChild(container) 88 | @instance = null 89 | delete @instance 90 | 91 | describe '#load()', -> 92 | beforeEach -> 93 | load_template_as_karma_html2js 'html1', html_template1 94 | load_template_as_karma_html2js 'html2', html_template2 95 | load_template_as_karma_html2js 'html3', html_template3 96 | load_template_as_karma_html2js 'html4', html_template4 97 | load_template_as_karma_html2js 'html5', html_template5 98 | load_template_as_karma_html2js 'html6', html_template6 99 | load_template_as_karma_json_fixures 'json.json', json_template 100 | load_template_as_karma_json_fixures 'escaped_json.json', escaped_json_template 101 | 102 | afterEach -> 103 | cleanup_karma_html2js_templates() 104 | 105 | it 'creates DOM elements inside the container from the template whose name is passed as the first param', -> 106 | @instance.load 'html1' 107 | expect(@fixture_cont.children.length).to.equal 1 108 | 109 | it 'accepts an "append" boolean as second param', -> 110 | @instance.load 'html1', true 111 | expect(@fixture_cont.children.length).to.equal 1 112 | 113 | it 'appends new template to existing one if append is true', -> 114 | @instance.load 'html1', false 115 | @instance.load 'html2', true 116 | @instance.load 'html1', true 117 | expect(@fixture_cont.children.length).to.equal 4 118 | 119 | it 'replaces older templates with new one if append is false', -> 120 | @instance.load 'html1', false 121 | @instance.load 'html2', false 122 | @instance.load 'html1', false 123 | expect(@fixture_cont.children.length).to.equal 1 124 | 125 | it 'has a default value of false', -> 126 | @instance.load 'html1' 127 | @instance.load 'html1' 128 | expect(@fixture_cont.children.length).to.equal 1 129 | 130 | it 'returns an array with a list of newly created dom nodes per template', -> 131 | dom_nodes = @instance.load('html1') 132 | 133 | expect(dom_nodes[0]) 134 | .to.equal @fixture_cont.firstChild 135 | 136 | it 'returns references to all firstChildren nodes created by the template', -> 137 | dom_nodes = @instance.load('html2') 138 | 139 | expect(dom_nodes.length) 140 | .to.equal(@fixture_cont.children.length) 141 | .to.equal(2) 142 | 143 | it 'throws when template does not exist', -> 144 | fn = => @instance.load('notExistingFixture') 145 | fixture_path = "#{@instance.base}/notExistingFixture" 146 | expect(fn).to.throw(ReferenceError, "Cannot find fixture '#{fixture_path}'") 147 | 148 | it 'ignores base if fixture name starts with \'/\'', -> 149 | load_template_as_karma_html2js 'html4', '
test
', 'test_base' 150 | 151 | @instance.load('/test_base/html4') 152 | expect(@fixture_cont.innerHTML).to.equal('test
') 153 | 154 | context 'when template contains