|
1 |
| -var writer = require('../src/writer.js'); |
| 1 | +var writer, |
| 2 | + rewire = require('rewire'); |
| 3 | + |
| 4 | +function mockResolvedPromise(resolvedValue) { |
| 5 | + return { |
| 6 | + then: function(success, failure) { |
| 7 | + success(resolvedValue); |
| 8 | + } |
| 9 | + }; |
| 10 | +} |
| 11 | + |
2 | 12 | describe('writer', function() {
|
| 13 | + |
| 14 | + beforeEach(function() { |
| 15 | + writer = rewire('../src/writer.js'); |
| 16 | + }); |
| 17 | + |
3 | 18 | describe('toString', function() {
|
4 |
| - var toString = writer.toString; |
| 19 | + var toString; |
| 20 | + |
| 21 | + beforeEach(function() { |
| 22 | + toString = writer.toString; |
| 23 | + }); |
5 | 24 |
|
6 | 25 | it('should merge string', function() {
|
7 | 26 | expect(toString('abc')).toEqual('abc');
|
@@ -31,4 +50,15 @@ describe('writer', function() {
|
31 | 50 | expect(content).toBe('ng super jqlite manifest');
|
32 | 51 | });
|
33 | 52 | });
|
| 53 | + |
| 54 | + describe('copy', function() { |
| 55 | + it('should call the transformation function', function() { |
| 56 | + var readMock = jasmine.createSpy('readMock').andReturn(mockResolvedPromise('DUMMY CONTENT')); |
| 57 | + writer.__set__("qfs.read", readMock); |
| 58 | + var transformationFn = jasmine.createSpy('transformationFn'); |
| 59 | + writer.copy('from', 'to', transformationFn, 'arg1', 'arg2'); |
| 60 | + expect(readMock).toHaveBeenCalled(); |
| 61 | + expect(transformationFn).toHaveBeenCalledWith('DUMMY CONTENT', 'arg1', 'arg2'); |
| 62 | + }); |
| 63 | + }); |
34 | 64 | });
|
0 commit comments