@ -10,7 +10,16 @@ import {
const mountedContainers = new Set ( )
const mountedContainers = new Set ( )
const mountedScopes = new Set ( )
const mountedScopes = new Set ( )
function render ( ui , { container , baseElement = container , queries , scope } = { } ) {
function render (
ui ,
{
container ,
baseElement = container ,
queries ,
scope ,
ignoreUnknownElements ,
} = { } ,
) {
if ( ! baseElement ) {
if ( ! baseElement ) {
// default to document.body instead of documentElement to avoid output of potentially-large
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
// head elements (such as JSS style blocks) in debug output
@ -37,6 +46,10 @@ function render(ui, {container, baseElement = container, queries, scope} = {}) {
$scope . $digest ( )
$scope . $digest ( )
if ( ! ignoreUnknownElements ) {
assertNoUnknownElements ( container )
}
return {
return {
container ,
container ,
baseElement ,
baseElement ,
@ -85,6 +98,26 @@ function cleanupScope(scope) {
mountedScopes . delete ( scope )
mountedScopes . delete ( scope )
}
}
function toCamel ( s ) {
return s
. toLowerCase ( )
. replace ( /-([a-z])/g , ( _ , letter ) => letter . toUpperCase ( ) )
}
function assertNoUnknownElements ( element ) {
const { tagName } = element
if ( tagName . includes ( '-' ) ) {
const $injector = getAngularService ( '$injector' )
const directiveName = ` ${ toCamel ( tagName ) } Directive `
if ( ! $injector . has ( directiveName ) ) {
throw Error (
` Unknown component/directive " ${ tagName } ". Are you missing an import? ` ,
)
}
}
Array . from ( element . children ) . forEach ( assertNoUnknownElements )
}
function getAngularService ( name ) {
function getAngularService ( name ) {
let service
let service
angular . mock . inject ( [
angular . mock . inject ( [