Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

48 wiersze
1.7KB

  1. var assert = require("assert");
  2. var vows = require("vows");
  3. var Context = require("./../mustache").Context;
  4. vows.describe("Mustache.Context").addBatch({
  5. "A Context": {
  6. topic: function () {
  7. var view = { name: 'parent', message: 'hi', a: { b: 'b' } };
  8. var context = new Context(view);
  9. return context;
  10. },
  11. "should be able to lookup properties of its own view": function (context) {
  12. assert.equal(context.lookup("name"), "parent");
  13. },
  14. "should be able to lookup nested properties of its own view": function (context) {
  15. assert.equal(context.lookup("a.b"), "b");
  16. },
  17. "when pushed": {
  18. topic: function (context) {
  19. var view = { name: 'child', c: { d: 'd' } };
  20. return context.push(view);
  21. },
  22. "should return the child context": function (context) {
  23. assert.equal(context.view.name, "child");
  24. assert.equal(context.parent.view.name, "parent");
  25. },
  26. "should be able to lookup properties of its own view": function (context) {
  27. assert.equal(context.lookup("name"), "child");
  28. },
  29. "should be able to lookup properties of the parent context's view": function (context) {
  30. assert.equal(context.lookup("message"), "hi");
  31. },
  32. "should be able to lookup nested properties of its own view": function (context) {
  33. assert.equal(context.lookup("c.d"), "d");
  34. },
  35. "should be able to lookup nested properties of its parent view": function (context) {
  36. assert.equal(context.lookup("a.b"), "b");
  37. }
  38. } // when pushed
  39. }, // A Context
  40. "make": {
  41. "should return the same object when given a Context": function () {
  42. var context = new Context;
  43. assert.strictEqual(Context.make(context), context);
  44. }
  45. }
  46. }).export(module);