forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE ember-string-ishtmlsafe] Added Ember.String.isHtmlSafe (embe…
…rjs/rfcs#139). Reintroduced deprecation of `new Ember.Handlebars.SafeString()`.
- Loading branch information
1 parent
7be41f7
commit 20080fc
Showing
9 changed files
with
138 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import EmberHandlebars from 'ember-htmlbars/compat'; | ||
import { isHtmlSafe } from 'ember-htmlbars/utils/string'; | ||
import { TestCase } from '../utils/abstract-test-case'; | ||
import { moduleFor } from '../utils/test-case'; | ||
|
||
|
||
moduleFor('compat - SafeString', class extends TestCase { | ||
['@test using new results in a deprecation']() { | ||
let result; | ||
|
||
expectDeprecation(() => { | ||
result = new EmberHandlebars.SafeString('<b>test</b>'); | ||
}, 'Ember.Handlebars.SafeString is deprecated in favor of Ember.String.htmlSafe'); | ||
|
||
this.assert.equal(result.toHTML(), '<b>test</b>'); | ||
|
||
// Ensure this functionality is maintained for backwards compat, but also deprecated. | ||
expectDeprecation(() => { | ||
this.assert.ok(result instanceof EmberHandlebars.SafeString); | ||
}, 'Ember.Handlebars.SafeString is deprecated in favor of Ember.String.htmlSafe'); | ||
} | ||
|
||
['@test isHtmlSafe should detect SafeString']() { | ||
let safeString; | ||
|
||
expectDeprecation(() => { | ||
safeString = new EmberHandlebars.SafeString('<b>test</b>'); | ||
}, 'Ember.Handlebars.SafeString is deprecated in favor of Ember.String.htmlSafe'); | ||
|
||
this.assert.ok(isHtmlSafe(safeString)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SafeString from 'htmlbars-util/safe-string'; | ||
import { htmlSafe, isHtmlSafe } from 'ember-htmlbars/utils/string'; | ||
import isEnabled from 'ember-metal/features'; | ||
import { TestCase } from './abstract-test-case'; | ||
import { moduleFor } from './test-case'; | ||
|
||
moduleFor('SafeString', class extends TestCase { | ||
['@test htmlSafe should return an instance of SafeString']() { | ||
let safeString = htmlSafe('you need to be more <b>bold</b>'); | ||
|
||
this.assert.ok(safeString instanceof SafeString, 'should be a SafeString'); | ||
} | ||
|
||
['@test htmlSafe should return an empty string for null']() { | ||
let safeString = htmlSafe(null); | ||
|
||
this.assert.equal(safeString instanceof SafeString, true, 'should be a SafeString'); | ||
this.assert.equal(safeString.toString(), '', 'should return an empty string'); | ||
} | ||
|
||
['@test htmlSafe should return an instance of SafeString']() { | ||
let safeString = htmlSafe(); | ||
|
||
this.assert.equal(safeString instanceof SafeString, true, 'should be a SafeString'); | ||
this.assert.equal(safeString.toString(), '', 'should return an empty string'); | ||
} | ||
}); | ||
|
||
if (isEnabled('ember-string-ishtmlsafe')) { | ||
moduleFor('SafeString isHtmlSafe', class extends TestCase { | ||
['@test isHtmlSafe should detect SafeString']() { | ||
let safeString = htmlSafe('<em>Emphasize</em> the important things.'); | ||
|
||
this.assert.ok(isHtmlSafe(safeString)); | ||
} | ||
|
||
['@test isHtmlSafe should not detect SafeString on primatives']() { | ||
this.assert.notOk(isHtmlSafe('Hello World')); | ||
this.assert.notOk(isHtmlSafe({})); | ||
this.assert.notOk(isHtmlSafe([])); | ||
this.assert.notOk(isHtmlSafe(10)); | ||
this.assert.notOk(isHtmlSafe(null)); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../ember-glimmer/tests/compat/safe-string-test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../ember-glimmer/tests/utils/string-test.js |
This file was deleted.
Oops, something went wrong.