import { haveText, html, test } from '../utils' export function setupConsoleInterceptor( ...targetIds ) { const mappedTargetIds = targetIds.map( tid => `'${tid}'` ).join( ',' ) return ` let errorContainer = document.createElement('div'); errorContainer.id = 'errors' errorContainer.textContent = 'false' document.querySelector('#root').after(errorContainer) console.warnlog = console.warn.bind(console) console.warn = function () { document.getElementById( 'errors' ).textContent = [${mappedTargetIds}].some( target => arguments[1] === document.getElementById( target ) ) console.warnlog.apply(console, arguments) } ` } export function assertConsoleInterceptorHadErrorWithCorrectElement() { return ({get}) => { get('#errors').should(haveText('true')) }; } test('x-for identifier issue', [html`
`, setupConsoleInterceptor( "xfor" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-text identifier issue', [html`
`, setupConsoleInterceptor( "xtext" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-init identifier issue', [html`
`, setupConsoleInterceptor( "xinit" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-show identifier issue', [html`
`, setupConsoleInterceptor( "xshow" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-bind class object syntax identifier issue', [html`
`, setupConsoleInterceptor( "xbind" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-model identifier issue', [html`
`, setupConsoleInterceptor( "xmodel" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-if identifier issue', [html`
`, setupConsoleInterceptor( "xif" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-if identifier issue ( function )', [html`
`, setupConsoleInterceptor( "xif" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-effect identifier issue', [html`
`, setupConsoleInterceptor( "xeffect" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-on identifier issue', [html`
`, setupConsoleInterceptor( "xon" ) ], ({ get }) => { get( "#xon" ).click() get( "#errors" ).should(haveText('true')) }, true ) test('x-data syntax error', [html`
`, setupConsoleInterceptor( "xdata" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('if statement syntax error', [html`
`, setupConsoleInterceptor( "xtext" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('x-data with reference error and multiple errors', [html`
`, setupConsoleInterceptor( "xdata", "xtext" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true ) test('evaluation with syntax error', [html`
`, setupConsoleInterceptor( "xif" ) ], assertConsoleInterceptorHadErrorWithCorrectElement(), true )