7a137094a866ddcb35c65a75e89f150c85c2f71c
[ccsdk/features.git] /
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this software except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 describe("app.ux.singleton", function(){
17
18 var Singleton = window.app.ux.Singleton;
19
20         describe("creating a singleton", function() {
21                 var X = Singleton.extend({
22                         foo: function() {
23                                 return "bar";
24                         }
25                 });
26
27                 var Y = Singleton.extend({
28                         bar: function() {
29                                 return "baz";
30                         }
31                 });
32
33                 it("should have properties like a normal class", function() {
34                         var a = X.instance();
35
36                         expect( a instanceof X ).toBe( true );
37                         expect( a.foo() ).toBe( "bar" );
38                 });
39
40                 it("should return single instance each time instance() is called", function() {
41                         var a = X.instance();
42                         var b = X.instance();
43
44                         expect( a ).toBe( b );
45                 });
46
47                 it("should not share instances with different singletons", function() {
48                         var a = X.instance();
49                         var c = Y.instance();
50
51                         expect( a ).not.toBe( c );
52                 });
53
54         });
55
56 });