Sha256: 5cec96064122f740bf8a8bc042f64557df06a5ee1db76b1af399e452692717be

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))

module Johnson
  module Extensions
    class DefinePropertyTest < Johnson::TestCase
      def setup
        super
        @runtime.evaluate("x = {}")
      end      
      
      def test_object_can_define_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42)")
        assert_js_equal(42, "x.answer")
      end
      
      def test_object_can_define_unenumerable_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42)")
        @runtime.evaluate <<-JS
          y = [];
          for(prop in x) if(prop == "answer") y.push(prop)
        JS
        assert_js("y.length == 0")
      end
      
      def test_object_can_define_enumerable_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42, Object.ITERABLE)")
        @runtime.evaluate <<-JS
          y = [];
          for(prop in x) if(prop == "answer") y.push(prop)
        JS
        assert_js("y.length == 1")
      end
      
      def test_object_can_define_read_only_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42, Object.READ_ONLY)")
        @runtime.evaluate("x.answer = 47")
        assert_js_equal(42, "x.answer")
      end
      
      def test_object_can_define_non_deletable_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42, Object.NON_DELETABLE)")
        @runtime.evaluate("r = (delete x.answer)")
        assert_js_equal(false, "r")
        assert_js_equal(42, "x.answer")
      end
      
      def test_object_can_define_mixed_property
        @runtime.evaluate("Object.defineProperty(x, 'answer', 42, Object.NON_DELETABLE | Object.READ_ONLY)")
        @runtime.evaluate("r = (delete x.answer)")
        @runtime.evaluate("x.answer = 47")
        assert_js_equal(false, "r")
        assert_js_equal(42, "x.answer")
      end      
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
jbarnette-johnson-1.0.0.200806240111 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.200807291507 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.200808062051 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.200808062111 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.200811251942 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20081126120511 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090127202936 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090225110820 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090326122910 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090326154650 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090326161333 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090402144841 test/johnson/extensions_test.rb
jbarnette-johnson-1.0.0.20090402155420 test/johnson/extensions_test.rb
johnson-1.2.0 test/johnson/extensions_test.rb
johnson-1.1.1 test/johnson/extensions_test.rb
johnson-1.1.2 test/johnson/extensions_test.rb
johnson-1.1.0 test/johnson/extensions_test.rb