|
| 1 | +import SafeString from 'htmlbars-util/safe-string'; |
| 2 | +import { htmlSafe, isHtmlSafe } from 'ember-htmlbars/utils/string'; |
| 3 | +import isEnabled from 'ember-metal/features'; |
| 4 | +import { TestCase } from './abstract-test-case'; |
| 5 | +import { moduleFor } from './test-case'; |
| 6 | + |
| 7 | +moduleFor('SafeString', class extends TestCase { |
| 8 | + ['@test htmlSafe should return an instance of SafeString']() { |
| 9 | + let safeString = htmlSafe('you need to be more <b>bold</b>'); |
| 10 | + |
| 11 | + this.assert.ok(safeString instanceof SafeString, 'should be a SafeString'); |
| 12 | + } |
| 13 | + |
| 14 | + ['@test htmlSafe should return an empty string for null']() { |
| 15 | + let safeString = htmlSafe(null); |
| 16 | + |
| 17 | + this.assert.equal(safeString instanceof SafeString, true, 'should be a SafeString'); |
| 18 | + this.assert.equal(safeString.toString(), '', 'should return an empty string'); |
| 19 | + } |
| 20 | + |
| 21 | + ['@test htmlSafe should return an instance of SafeString']() { |
| 22 | + let safeString = htmlSafe(); |
| 23 | + |
| 24 | + this.assert.equal(safeString instanceof SafeString, true, 'should be a SafeString'); |
| 25 | + this.assert.equal(safeString.toString(), '', 'should return an empty string'); |
| 26 | + } |
| 27 | +}); |
| 28 | + |
| 29 | +if (isEnabled('ember-string-ishtmlsafe')) { |
| 30 | + moduleFor('SafeString isHtmlSafe', class extends TestCase { |
| 31 | + ['@test isHtmlSafe should detect SafeString']() { |
| 32 | + let safeString = htmlSafe('<em>Emphasize</em> the important things.'); |
| 33 | + |
| 34 | + this.assert.ok(isHtmlSafe(safeString)); |
| 35 | + } |
| 36 | + |
| 37 | + ['@test isHtmlSafe should not detect SafeString on primatives']() { |
| 38 | + this.assert.notOk(isHtmlSafe('Hello World')); |
| 39 | + this.assert.notOk(isHtmlSafe({})); |
| 40 | + this.assert.notOk(isHtmlSafe([])); |
| 41 | + this.assert.notOk(isHtmlSafe(10)); |
| 42 | + this.assert.notOk(isHtmlSafe(null)); |
| 43 | + } |
| 44 | + }); |
| 45 | +} |
0 commit comments