From afcf28ab199df5e137069c48de087e5c80bd77fa Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sat, 31 Dec 2016 09:38:35 -0500 Subject: [PATCH] more documentation --- docs/guides.md | 2 ++ docs/introduction.md | 7 ++++--- docs/testing.md | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/docs/guides.md b/docs/guides.md index a4333b58..3b3c537c 100644 --- a/docs/guides.md +++ b/docs/guides.md @@ -11,6 +11,8 @@ - [Keys](keys.md) - Social - [Community chat](https://gitter.im/lhorie/mithril.js) + - [Wiki](https://github.com/lhorie/mithril.js/wiki) + - [Jobs](https://github.com/lhorie/mithril.js/wiki/JOBS) - [Contributing](contributing.md) - [Credits](credits.md) - Misc diff --git a/docs/introduction.md b/docs/introduction.md index 2e451a7d..9a59f3b8 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -12,15 +12,16 @@ ### What is Mithril? -Mithril is a client-side Javascript framework for building Single Page Applications. It's small and batteries-included. +Mithril is a client-side Javascript framework for building Single Page Applications. +It's small (< 8kb gzip) and batteries-included. If you are an experienced developer and want to know how Mithril compares to other frameworks, see the [framework comparison](framework-comparison.md) page. --- -### Getting started +Note: This introduction assumes you have basic level of Javacript knowledge. If you don't, there are many great resources to learn. [Speaking Javascript](http://speakingjs.com/es5/index.html) is a good e-book for absolute beginners. If you're already familiar with other programming languages, the [Eloquent Javascript](http://eloquentjavascript.net/) e-book might be more suitable for you. [Codecademy](https://www.codecademy.com/learn/javascript) is another good resource that emphasizes learning via interactivity. -This introduction assumes you know Javacript. If you don't, there are many great resources to learn. [Speaking Javascript](http://speakingjs.com/es5/index.html) is a good e-book for absolute beginners. If you're already familiar with other programming languages, the [Eloquent Javascript](http://eloquentjavascript.net/) e-book might be more suitable for you. [Codecademy](https://www.codecademy.com/learn/javascript) is another good resource that emphasizes learning via interactivity. +### Getting started The easiest way to try out Mithril is to include it from a CDN, and follow this tutorial. It'll cover the majority of the API surface but it'll only take 10 minutes. diff --git a/docs/testing.md b/docs/testing.md index ad4aaba0..b2615649 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -44,3 +44,42 @@ Writing tests upfront requires specifications to be frozen. Upfront tests are a Writing tests after the fact is a way to document the behavior of a system and avoid regressions. They are useful to ensure that obscure corner cases are not inadvertedly broken and that previously fixed bugs do not get re-introduced by unrelated changes. +--- + +### Unit testing + +Unit testing is the practice of isolating a part of an application (typically a single module), and asserting that, given some inputs, it produces the expected outputs. + +Testing a Mithril component is easy. Let's assume we have a simple component like this: + +```javascript +// MyComponent.js +var m = require("mithril") + +module.exports = { + view: function() { + return m("div", "Hello world") + } +} +``` + +We can then create a `tests/MyComponent.js` file and create a test for this component like this: + +``` +var MyComponent = require("MyComponent") + +o.spec("MyComponent", function() { + o("returns a div", function() { + var vnode = MyComponent.view() + + o(vnode.tag).equals("div") + o(vnode.children.length).equals(1) + o(vnode.children[0].tag).equals("#") + o(vnode.children[0].children).equals("Hello world") + }) +}) +``` + +Typically, you wouldn't test the structure of the vnode tree so granularly, and you would instead only test non-trivial, dynamic aspects of the view. A tool that can help making testing easier with deep vnode trees is [Mithril Query](https://github.com/StephanHoyer/mithril-query). + +Sometimes, you need to mock the dependencies of a module in order to test the module in isolation. [Mockery](https://github.com/mfncooper/mockery) is one tool that allows you to do that.