Skip to content

Commit

Permalink
Added optional test unset behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Sep 28, 2023
1 parent 7b56333 commit 2c63532
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nui/test/nui/test_attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,20 @@ namespace Nui::Tests

EXPECT_EQ(Nui::val::global("document")["body"]["attributes"]["id"].as<std::string>(), "A");
}

TEST_F(TestAttributes, OptionalIsUnsetByObserved)
{
using Nui::Elements::div;
using Nui::Attributes::id;

Observed<std::optional<std::string>> idValue{std::string{"A"}};

render(div{id = idValue}());
EXPECT_EQ(Nui::val::global("document")["body"]["attributes"]["id"].as<std::string>(), "A");

idValue = std::nullopt;
globalEventContext.executeActiveEventsImmediately();

EXPECT_FALSE(Nui::val::global("document")["body"]["attributes"].hasOwnProperty("id"));
}
}

0 comments on commit 2c63532

Please sign in to comment.