Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
mojito-markup-test
Advanced tools
The markup layout test utility will render the mojit view with mock data and expose the resulting markup to be validated using YUI Node module.
Markup tests written with this utility will be run as regular mojito unit tests
using mojito test
command
Three easy steps:
mojito-markup-test
.spec
.You must specify the mojit and view to render, along with the mock data to use.
You can mock any data, including parameters, configuration, request and headers.
//describe the mojit to render
spec = {
//mojit type (dir name)
type: 'SimpleMojit',
//action to test
action: 'index',
//mojit params
params: {
url: {
p: 'Really!'
}
},
//mojit config (to use with ac.config.get() )
appConfig: {
foo: 'bar'
},
//mock request/response and headers data
req: {
p: 'flowers'
},
res: {},
headers: {
'Content-Type': 'text/html'
}
};
Once you have the mojit spec, you can render the view invoking the utility's render
method.
Receives the mojit spec and a callback function which will get the error (if any), the rendered markup string, the mojit view meta object and the node (YUI Node) for the resulting markup.
MarkupTest.render(spec, function (err, markup, meta, node) {
//rendering done, resume paused test and verify
test.resume(function () {
var div, em, i, a, text;
A.isNull(err);
//we have markup
A.areNotEqual('', markup, 'Markup');
//we have meta
A.isNotNull(meta, 'Meta');
//we have a node
A.isNotUndefined(node, 'Parent node');
A.isNotNull(node, 'Parent node');
//use YUI Node methods to access rendered elements
div = node.one('.msg');
A.isNotUndefined(div, 'msg <div>');
A.isNotNull(div, 'msg <div>');
});
YUI.add('CompositeMojit_view-tests', function(Y) {
var suite = new YUITest.TestSuite('CompositeMojit'),
A = YUITest.Assert,
MarkupTest = Y.mojito.MarkupTest,
//Timeout for async testing
TIMEOUT = 1000;
suite.add(new YUITest.TestCase({
name: 'view',
'test index': function () {
var test = this,
//describe the mojit to render
spec = {
//mojit type (dir name)
type: 'CompositeMojit',
//action to test
action: 'index',
//mojit params
params: {
url: {
p: 'Really!'
}
},
//mojit config (to use with ac.config.get() )
config: {
foo: 'bar'
},
//app level config (to use with ac.app)
appConfig: {
some: 'config param'
},
// We need to define the child mojits,
// modules should be in the requires: [] as well to be loaded (see below)
children: {
'child_mojit': {
type: 'ChildMojit'
}
}
};
MarkupTest.render(spec, function (err, markup, meta, node) {
//rendering done, resume paused test and verify
test.resume(function () {
var div, em, i, a, text;
A.isNull(err);
//we have markup
A.areNotEqual('', markup, 'Markup');
//we have meta
A.isNotNull(meta, 'Meta');
//we have a node
A.isNotUndefined(node, 'Parent node');
A.isNotNull(node, 'Parent node');
div = node.one('.msg');
A.isNotUndefined(div, 'msg <div>');
A.isNotNull(div, 'msg <div>');
em = div.one('em');
A.isNotUndefined(em, '<em>');
A.isNotNull(em, '<em>');
text = em.getContent();
A.areEqual('Mojito is working.', text, 'Rendered message <em>');
i = div.one('i');
A.isNotUndefined(i, '<i>');
A.isNotNull(i, '<i>');
text = i.getContent();
A.areEqual(spec.params.url.p, text, 'Rendered message <i>');
a = div.one('a');
A.isNotUndefined(a, '<a>');
A.isNotNull(a, '<a>');
text = a.getContent();
A.areEqual(spec.config.foo, text, 'Rendered message <a>');
});
});
//we need this for async tests, wait till rendering done or timeout
test.wait(TIMEOUT);
}
}));
YUITest.TestRunner.add(suite);
}, '0.0.1', {requires: [
'mojito-test',
//test rendering utility
'mojito-markup-test'
//parent mojit
'CompositeMojit',
//child mojit
'ChildMojit'
]});
See more examples.
FAQs
Utility for view markup validation in mojito unit tests.
The npm package mojito-markup-test receives a total of 15 weekly downloads. As such, mojito-markup-test popularity was classified as not popular.
We found that mojito-markup-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.