From 05bda05ad7061330ce929be4a6fc3d3c80fb57c2 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 20 Oct 2022 12:53:02 +0200 Subject: [PATCH] started Task 3 --- jasmine_demo/index.js | 3 ++- jasmine_demo/lib/parse-to-proto.js | 7 +++++++ jasmine_demo/spec/parse-to-proto-Specs.js | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 jasmine_demo/lib/parse-to-proto.js create mode 100644 jasmine_demo/spec/parse-to-proto-Specs.js diff --git a/jasmine_demo/index.js b/jasmine_demo/index.js index e9b8901..5c08601 100644 --- a/jasmine_demo/index.js +++ b/jasmine_demo/index.js @@ -7,4 +7,5 @@ const meinPlayer = new Player() meinPlayer.play(meinSong) if(meinPlayer.isPlaying){ console.log(meinPlayer.currentlyPlayingSong.title) -} \ No newline at end of file +} + diff --git a/jasmine_demo/lib/parse-to-proto.js b/jasmine_demo/lib/parse-to-proto.js new file mode 100644 index 0000000..ab3cd49 --- /dev/null +++ b/jasmine_demo/lib/parse-to-proto.js @@ -0,0 +1,7 @@ +function parseToProto(json, proto){ + return Object.assign(Object.create(proto), JSON.parse(json)) +} + + + +module.exports = { parseToProto} \ No newline at end of file diff --git a/jasmine_demo/spec/parse-to-proto-Specs.js b/jasmine_demo/spec/parse-to-proto-Specs.js new file mode 100644 index 0000000..0344c13 --- /dev/null +++ b/jasmine_demo/spec/parse-to-proto-Specs.js @@ -0,0 +1,15 @@ +describe("parseToProto", function() { + var obj; + + beforeEach(function() { + let proto = {category: "animal"} + }); + + it("should have category, type, name and age attribute", function() { + let obj = parseToProto('{"type": "cat", "name":"Mimi","age":3}', proto) + expect("animal").toEqual(obj.category); + expect("cat").toEqual(obj.type); + expect("Mimi").toEqual(obj.name); + expect(3).toEqual(obj.age); + }); +}); \ No newline at end of file