mirror of
https://gitlab.com/nightlycommit/twing.git
synced 2025-01-18 08:46:50 +02:00
Merge branch 'issue-599' into 'main'
Resolve issue #599 Closes #599 See merge request nightlycommit/twing!595
This commit is contained in:
commit
52b1b65753
@ -127,7 +127,7 @@ export interface TwingEnvironment {
|
||||
*
|
||||
* When a template is encountered, Twing environment emits a `template` event with the name of the encountered template and the source of the template that initiated the loading.
|
||||
*/
|
||||
on(eventName: "load", listener: (name: string, from: TwingSource | null) => void): void;
|
||||
on(eventName: "load", listener: (name: string, from: string | null) => void): void;
|
||||
|
||||
/**
|
||||
* Converts a token list to a template.
|
||||
|
@ -2,6 +2,7 @@ import * as tape from "tape";
|
||||
import {createEnvironment} from "../../../../../src/lib/environment";
|
||||
import {createFilesystemLoader, TwingFilesystemLoaderFilesystem} from "../../../../../src/lib/loader/filesystem";
|
||||
import {spy} from "sinon";
|
||||
import {createArrayLoader} from "../../../../../src/lib/loader/array";
|
||||
|
||||
tape('createEnvironment::loadTemplate', ({test}) => {
|
||||
test('cache the loaded template under it fully qualified name', ({same, end}) => {
|
||||
@ -40,4 +41,29 @@ tape('createEnvironment::loadTemplate', ({test}) => {
|
||||
})
|
||||
.finally(end);
|
||||
});
|
||||
|
||||
test('emits a "load" event', ({same, end}) => {
|
||||
const environment = createEnvironment(createArrayLoader({
|
||||
index: `{{ include("partial") }}`,
|
||||
partial: ``
|
||||
}));
|
||||
|
||||
const loadedTemplates: Array<[string, string | null]> = [];
|
||||
|
||||
environment.on("load", (name, from) => {
|
||||
loadedTemplates.push([name, from]);
|
||||
});
|
||||
|
||||
return environment.loadTemplate(('index'))
|
||||
.then((template) => {
|
||||
return template.render({});
|
||||
})
|
||||
.then(() => {
|
||||
same(loadedTemplates, [
|
||||
['index', null],
|
||||
['partial', 'index']
|
||||
]);
|
||||
})
|
||||
.finally(end);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user